public bool ResetPassword(string login, string document, string newPassword) { try { Users userModel = repository.filter(u => u.login.Equals(login) && u.document.Equals(document) && u.active).SingleOrDefault(); UserEntity user = convertModelToEntity(userModel); if (user != null) { var keyNew = CryptographySHA1.GeneratePassword(10); var password = CryptographySHA1.EncodePassword(newPassword, keyNew); user.password = password; user.verificationCode = keyNew; base.update(ref user); sendEmailUser(user, newPassword); return(true); } throw new ArgumentException("Login or Document are Incorrent!"); } catch (Exception ex) { throw ex; } }
public void Login([Bind(Include = "login, password")] LoginViewModel model) { try { if (ModelState.IsValid) { UserEntity user = userService.Get(model.login); if (user != null) { var hashCode = user.verificationCode; var encodingPasswordString = CryptographySHA1.EncodePassword(model.password, hashCode); if (user.password.Equals(encodingPasswordString)) { Session["name"] = user.nickName; Session["permissions"] = caService.GetPermissions(user.UserID); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, model.login, DateTime.Now, DateTime.Now.AddHours(1), true, user.UserID.ToString(), FormsAuthentication.FormsCookiePath); string encryptedTicket = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); cookie.HttpOnly = true; cookie.Expires = DateTime.Now.AddHours(1); Response.Cookies.Add(cookie); Response.Redirect(@"~/Projects/Index", false); } else { Response.Redirect(@"~/Login/Login", false); ModelState.AddModelError(string.Empty, "Login or Password are Incorrect!"); } } else { Response.Redirect(@"~/Login/Login", false); ModelState.AddModelError(string.Empty, "Login or Password are Incorrect!"); } } } catch (Exception ex) { throw ex; } }
public override void add(ref UserEntity entity, bool persistir = true) { try { string randomPassword = Membership.GeneratePassword(6, 1); var keyNew = CryptographySHA1.GeneratePassword(10); var password = CryptographySHA1.EncodePassword(randomPassword, keyNew); entity.password = password; entity.verificationCode = keyNew; entity.active = true; base.add(ref entity, persistir); sendEmailUser(entity, randomPassword); } catch (Exception ex) { throw ex; } }