Пример #1
0
        public static bool Validate(ChangePasswordRequestModel model, out string message)
        {
            bool fail = false;
            if(model.NewPassword == model.Password)
            {
                fail = true;
                message = "New password should not be same old password";
            }
            else if (model.NewPassword != model.NewPassword2)
            {
                fail = true;
                message = "Retyped password is not matched";
            }
            else
            {
                message = "Success";
            }

            return !fail;
        }
Пример #2
0
        public bool ChangePassword(ChangePasswordRequestModel item)
        {
            User user;
            if (_userRepo.TryGetItemById(item.UserId, out user))
            {
                if (Hasher.Check(item.Password, user.Password, user.Salt))
                {
                    var updated = _userRepo.Update(item.UserId, u =>
                    {
                        u.Salt = Hasher.GetSalt();
                        u.Password = Hasher.Hash(item.NewPassword, u.Salt);
                    });

                    if (updated)
                    {
                        return true;
                    }
                }
            }
            return false;
        }