예제 #1
0
        public async Task SignOutUserAsync(Users userToCreate, string plainPassword)
        {
            string passwordSalt = PasswordHashing.CreateSalt();

            userToCreate.PasswordSalt = passwordSalt;
            userToCreate.PasswordHash = PasswordHashing.GenerateHash(plainPassword, passwordSalt);

            await _context.Users.AddAsync(userToCreate);
        }
예제 #2
0
        public ActionResult SaveNewPassword(PasswordViewModel model)
        {
            var userId = Helpers.Authentication.GetUserID();

            var user = ctx.User.Find(userId);

            if (PasswordHashing.GenerateHash(model.OldPassword, user.PasswordSalt) == user.PasswordHash)
            {
                string newHash = PasswordHashing.GenerateHash(model.NewPassword, user.PasswordSalt);
                user.PasswordHash = newHash;
                ctx.SaveChanges();

                return(RedirectToAction("Index", "ProjectsManager"));
            }

            ModelState.AddModelError(String.Empty, "Neispravna stara lozinka. Molimo pokušajte ponovo.");

            return(View("Index", model));
        }