void Validate(string password)
        {
            var helper = new PasswordValidationHelper();

            this.IsValid         = helper.IsValid(password);
            this.ValidationError = helper.ValidationError;
        }
        public void UpdatePassword(User user, string password)
        {
            CheckLoginStatus();
            PasswordValidationHelper.ValidatePassword(password);

            var detailedUser = _db.Find("Username", user.Username).FirstOrDefault();

            detailedUser.SetPassword(password);

            _db.Update(detailedUser);
        }
예제 #3
0
        public CreateNewWalletPageViewModel(INavigationService navigationService, IPageDialogService dialogService)
            : base(navigationService, dialogService)
        {
            NextCommand = new DelegateCommand(() => {
                var helper = new PasswordValidationHelper();

                if (helper.IsValid(Password, ConfirmPassword))
                {
                    _navigationService.NavigateAsync(typeof(ShowWalletMasterKeyPage).Name + "?password="******"Warning", helper.ValidationError, "Ok");
                }
            });
        }
예제 #4
0
        public async Task ResetPassword(AuthenticationUser user, string oldPassword, string newPassword)
        {
            if (string.IsNullOrEmpty(newPassword))
            {
                throw new BadRequestException("Password reset failed, new password cannot be empty", ErrorCodes.EmptyPassword);
            }

            if (oldPassword != null && oldPassword == newPassword)
            {
                throw new BadRequestException("Password reset failed, new password cannot be equal to the old one", ErrorCodes.SamePassword);
            }

            if (newPassword.ToLower() == user.Login?.ToLower())
            {
                throw new BadRequestException("Password reset failed, new password cannot be equal to login name", ErrorCodes.PasswordSameAsLogin);
            }

            if (newPassword.ToLower() == user.DisplayName?.ToLower())
            {
                throw new BadRequestException("Password reset failed, new password cannot be equal to display name", ErrorCodes.PasswordSameAsDisplayName);
            }

            string errorMsg;

            if (!PasswordValidationHelper.ValidatePassword(newPassword, true, out errorMsg))
            {
                throw new BadRequestException("Password reset failed, new password is invalid", ErrorCodes.TooSimplePassword);
            }

            if (await IsChangePasswordCooldownInEffect(user))
            {
                throw new ConflictException("Password reset failed, password reset cooldown in effect", ErrorCodes.ChangePasswordCooldownInEffect);
            }

            if (!await _userRepository.ValidateUserPasswordForHistoryAsync(user.Id, newPassword))
            {
                throw new BadRequestException("The new password matches a previously used password.", ErrorCodes.PasswordAlreadyUsedPreviously);
            }

            var newGuid = Guid.NewGuid();

            user.UserSalt = newGuid;
            user.Password = HashingUtilities.GenerateSaltedHash(newPassword, user.UserSalt);

            await _userRepository.UpdateUserOnPasswordResetAsync(user);
        }
        public void StoreUser(User user, string password)
        {
            CheckLoginStatus();
            if (_db.Exists("Username", user.Username))
            {
                throw new ArgumentException($"Username '{ user.Username }' already exists.");
            }

            var newUser = new DetailedUser
            {
                Username    = user.Username,
                Name        = user.Name,
                LastName    = user.LastName,
                DateCreated = DateTime.Now
            };

            PasswordValidationHelper.ValidatePassword(password);
            newUser.SetPassword(password);

            _db.Add(newUser);
        }