public HttpResponseMessage ChangePassword(PasswordViewModel viewmodel)
        {
            if (ModelState.IsValid)
            {
                if (_userService.ChangePassword(viewmodel))
                {
                    return new HttpResponseMessage(HttpStatusCode.OK);
                }
            }

            return new HttpResponseMessage(HttpStatusCode.BadRequest);
        }
Example #2
0
        public bool ChangePassword(PasswordViewModel viewmodel)
        {
            var user = _unitOfWork.Users.Get(_ => _.Id == viewmodel.UserId);
            if (CompareHash(viewmodel.Current, user.Password, user.Salt))
            {
                user.Salt = CreateSalt();
                user.Password = Convert.ToBase64String(GetHash(viewmodel.NewPassword, user.Salt));
                _unitOfWork.Commit();
                return true;
            }

            return false;
        }