public ActionResult RenewPassword(RenewPSModel record) { PegasEntities DBContext = new PegasEntities(); var user = DBContext.Users.First(u => u.Username == record.UserName); string password = user.Password; string recipient = user.Password; SendEmail(recipient, password, record.UserName); TempData["Notification"] = "Your password sent to your email."; return(RedirectToAction("Login")); }
public bool DoesUserExist(string userName, string password) { PegasEntities DB = new PegasEntities(); bool userValidated = true; var user = DB.Users.FirstOrDefault(u => u.Username == userName); if (user != null) { if (user.Password == password) { userValidated = true; return(userValidated); } else { userValidated = false; } } return(false); //bool userValidated = true; //var domainContext = new PrincipalContext(ContextType.Domain, "BKK.PGS.DOM"); //var foundUser = UserPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, userName); //if (foundUser != null) //{ // if (domainContext.ValidateCredentials(userName, password)) // { // userValidated = true; // return userValidated; // } // else // { // userValidated = false; // } //} //return false; }
public ActionResult ChangePassword(ChangePSModel record) { User entity; string msg; using (PegasEntities context = new PegasEntities()) { if (record != null) { if (record.NewPassword == record.NewPasswordAgain) { entity = _userRepository.Get(p => p.Username == record.UserName); if (entity.Password == record.OldPassword) { entity.Password = record.NewPassword; context.SaveChanges(); } else { msg = "Your password cannot be changed, contact to your administrator."; TempData["ErrorMessage"] = msg; return(RedirectToAction("Account")); } } else { msg = "New passwords are not same, check new password."; TempData["ErrorMessage"] = msg; return(RedirectToAction("Account")); } } } msg = "Your password changed successfully."; TempData["ErrorMessage"] = msg; return(RedirectToAction("Account")); }
public PegasEntities Get() { return(dataContext ?? (dataContext = new PegasEntities())); }