Ejemplo n.º 1
0
        public void Validate_FromPregenerate_True()
        {
            const string hash  = "E2HJhN1F3/VBR0bcU7CJ7qsjNjIzQO225cujRckk1rA=";
            const string salt  = "blmCds9MPswKZ0+tJUqwsA==";
            const string value = "P@$sw0Rd";

            var saltyHash = new SaltyHash(hash, salt);

            Assert.IsTrue(saltyHash.Validate(value));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Login(LoginModel loginModel)
        {
            if (ModelState.IsValid)
            {
                var user = _userRepository.GetUserByEmail(loginModel.Email);
                if (user == null)
                {
                    ModelState.AddModelError("Email", "User with this email does not exist.");
                    return(View(loginModel));
                }

                var saltyHash = new SaltyHash(user.Hash, user.Salt);
                if (saltyHash.Validate(loginModel.Password))
                {
                    await Authenticate(loginModel.Email);

                    return(RedirectToAction("Index", "Home"));
                }
                ModelState.AddModelError("Password", "Please enter correct password.");
            }
            return(View(loginModel));
        }
Ejemplo n.º 3
0
        public IActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                var user      = _userRepository.GetUserByEmail(User.Identity.Name);
                var saltyHash = new SaltyHash(user.Hash, user.Salt);

                if (saltyHash.Validate(model.CurrentPassword))
                {
                    var newPassword = SaltyHash.Create(model.NewPassword);
                    (user.Hash, user.Salt) = (newPassword.Hash, newPassword.Salt);
                    _userRepository.UpdateEntity(user);
                    _userRepository.Save();
                    ViewData.Add("Success", "Password change was successful!");
                }
                else
                {
                    ModelState.AddModelError("CurrentPassword", "Please enter correct password.");
                }
            }
            return(View("Settings"));
        }