public EmployeeModel GetEmployee(EmployeeLoginBindingModel employeeModel) { using (this.employeeRepository) { EmployeeWithPasswordModel employeeWithPassword = this.employeeRepository.GetEmployeeWithPasswordByUsername(employeeModel.Username); if (employeeWithPassword == null) { return(null); } string actualPasswordHash = PasswordUtilities.GeneratePasswordHash(employeeModel.Password, employeeWithPassword.PasswordSalt); if (actualPasswordHash != employeeWithPassword.PasswordHash) { return(null); } EmployeeModel employee = new EmployeeModel(employeeWithPassword.Id, employeeWithPassword.Username); return(employee); } }
public ActionResult Login(EmployeeLoginBindingModel employeeModel) { if (!this.ModelState.IsValid) { return(this.View(employeeModel)); } EmployeeModel employee = this.employeeManager.GetEmployee(employeeModel); if (employee == null) { this.TempData.Add(TempDataErrorMessageKey, InvalidCredentials); return(this.View(employeeModel)); } this.Session[SessionUserKey] = employee; this.TempData.Add(TempDataSuccessMessageKey, LoginSuccessful); return(RedirectToAction(nameof(VotingsController.Index), Votings)); }