Last active
December 30, 2015 03:29
-
-
Save eldewall/7769639 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public ActionResult Login(LoginModel model) { | |
if (!ModelState.IsValid) { | |
return View(model); | |
} | |
if (UserValidator.IsValid(model)) { // USES REPOSITORY | |
FormsAuthentication.SetAuthCookie(model.Email, false); | |
var user = this.UserRepository.Get(model.Email); // USES IT AGAIN | |
BankIdValidator = new BankIdValidator(user, this.UserRepository); | |
BankIdValidator.InvalidateBankId(); | |
return Redirect(model.ReturnUrl); | |
} else { | |
ModelState.AddModelError("", "Ogiltigt användarnamn eller lösenord"); | |
return View(model); | |
} | |
} | |
från UserValidator | |
public bool IsValid(LoginModel model) { | |
var usr = UserRepository.Get(model.Email); | |
if (usr == null) { | |
return false; | |
} | |
var password = PasswordEncryption.HashPassword(model.Password, usr.Salt); | |
return usr.Password == password; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment