Exemplo n.º 1
0
        public static IdentityResult ChangePassword(int userId, string oldPassword, string newPassword)
        {
            IdentityResult result = new IdentityResult();

            var user = UserManager.SelectByUserId(userId);

            if (user != null)
            {
                if(Crypto.VerifyHashedPassword(user.PasswordHash, oldPassword))
                {
                    string newPasswordHash = Crypto.HashPassword(newPassword);
                    user.PasswordHash = newPasswordHash;
                    Write();
                    result.Success = true;
                }
                else
                {
                    result.Errors.Add("Old Password wrong.");
                }
            }
            else
            {
                result.Errors.Add("User not found.");
            }

            return result;
        }
Exemplo n.º 2
0
        public static IdentityResult CreateUser(User user, string password)
        {
            IdentityResult result = new IdentityResult();
            string hashedPassword = Crypto.HashPassword(password);

            Random rand = new Random();
            user.ID = rand.Next();
            user.PasswordHash = hashedPassword;

            Users.Add(user);
            Write();

            result.Success = true;

            return result;
        }
Exemplo n.º 3
0
 private void AddErrors(IdentityResult result)
 {
     foreach (var error in result.Errors)
     {
         ModelState.AddModelError("", error);
     }
 }