public IActionResult Register(RegisterBindingModel model) { if (model.Password != model.ConfirmPassword) { this.Model["error"] = "Passwords doesn't match!"; this.AutorizeUser(); return(View()); } var hashPassword = PasswordHash.ComputeSha256Hash(model.Password); var user = new User() { Username = model.Username, Email = model.Email, PasswordHash = hashPassword, }; this.service.RegisterUser(user); this.SignIn(model.Username); return(RedirectToAction("/")); }
public IActionResult Login(LoginBindingModel model) { var isUserExists = this.service.IsUserExist(model.Username); var user = this.service.GetUserByName(model.Username); var passwordHash = PasswordHash.ComputeSha256Hash(model.Password); if (user == null || user.PasswordHash != passwordHash) { this.Model["error"] = "username or password is wrong!"; this.AutorizeUser(); return(View()); } if (isUserExists) { this.SignIn(model.Username); this.InitializeUser(); } return(RedirectToAction("/")); }