Нужен простой и надежный способ хэширования пароля в контроллере AccountCOntroller
Выглядит он так:
public class AccountController : Controller {
private IAuthProvider authProvider;
private IUserRepository repository;
public AccountController(IAuthProvider auth, IUserRepository repo) {
authProvider = auth;
repository = repo;
}
public ViewResult Login() {
return View();
}
public ViewResult Register() {
return View();
}
[HttpPost]
public ActionResult Login(LoginViewModel model) {
if (ModelState.IsValid) {
User user = repository.Users().FirstOrDefault(m => m.Login == model.Login && m.Password == model.Password);
if(user != null) {
authProvider.Authenticate(model.Login);
return RedirectToAction("Index", "Document");
} else {
ModelState.AddModelError("", "Неверный логин или пароль");
}
}
return View(model);
}
[HttpPost]
public ActionResult Register(RegisterViewModel model) {
if (ModelState.IsValid) {
User user = repository.Users().FirstOrDefault(m => m.Login == model.Login);
if (user == null) {
repository.Add(new User { Login = model.Login, Password = model.Password });
user = repository.Users().Where(m => m.Login == model.Login && m.Password == model.Password).FirstOrDefault();
if (user != null) {
authProvider.Authenticate(model.Login);
return RedirectToAction("Index", "Document");
}
} else {
ModelState.AddModelError("", "Пользователь с таким логинм уже есть");
}
}
return View(model);
}
public ActionResult ExitToStore() {
authProvider.Exit();
return RedirectToAction("Login");
}
}