Пример #1
0
        public async Task <UserResultModel> ResetPasswordAsync(AppUser u, string token, string newPassword)
        {
            var res = new UserResultModel();

            if (!ValidatePasswordResetToken(u, token))
            {
                res.Errors.Add("Invalid token.");
                return(res);
            }

            if (!UserDataValidator.ValidatePassword(newPassword))
            {
                res.Errors.Add("Password does not meet minimum requirments.");
                return(res);
            }

            var newPwdHash = HashUserPassword(u, newPassword);

            u.PasswordHash = newPwdHash;

            _dbContext.Update(u);
            await _dbContext.SaveChangesAsync();

            return(res);
        }
Пример #2
0
        public async Task <UserResultModel> CreateAsync(AppUser u, string password)
        {
            var res = new UserResultModel();

            if (!UserDataValidator.ValidateEmail(u.Email))
            {
                res.Errors.Add("Invalid email address.");
            }
            if (!UserDataValidator.ValidateUserName(u.UserName))
            {
                res.Errors.Add("Invalid user name.");
            }
            if (!UserDataValidator.ValidateTarget(u.DailyTarget))
            {
                res.Errors.Add("Target has to be at least 0.");
            }
            if (!UserDataValidator.ValidatePassword(password))
            {
                res.Errors.Add("Password does not meet minimum requirments.");
            }

            if (!res.Succeeded)
            {
                return(res);                // stop and return all errors.
            }
            u.PasswordHash = HashUserPassword(u, password);
            _dbContext.Users.Add(u);
            await _dbContext.SaveChangesAsync();

            return(res);
        }
Пример #3
0
 /// <summary>
 /// Returns whether the given password is valid,
 /// And shows an error dialog if not.
 /// </summary>
 public static bool ValidatePassword(string password, Context context)
 {
     if (UserDataValidator.ValidatePassword(password))
     {
         return(true);
     }
     else
     {
         ShowErrorDialog("Password must include a lower case, an upper case," +
                         " a number and a special charachter, as well as at least 8 digits.", context);
         return(false);
     }
 }