Ejemplo n.º 1
0
        /// <summary>
        /// 返回的user中PasswordHash是存在数据库中的密码值,已经被hash过,并不是用户输入的密码
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public async ValueTask <RmanagerUser> AddUserAsync(RmanagerUser user)
        {
            var validater = new PasswordValidator();

            validater.SetLengthBounds(8, 20);
            validater.AddCheck(EzPasswordValidator.Checks.CheckTypes.Letters);
            validater.AddCheck(EzPasswordValidator.Checks.CheckTypes.Numbers);
            if (!validater.Validate(user.PassWordHash))
            {
                throw new _401Exception("Password is not strong enough!");
            }

            if (string.IsNullOrEmpty(user.Email) ||
                string.IsNullOrEmpty(user.Name) ||
                string.IsNullOrEmpty(user.PassWordHash))
            {
                throw new _401Exception("register data should not be null!");
            }

            await CheckEmailAndNameAsync(user);

            user.IsEmailConfirmed = false;
            user.AvatarUrl        = "";

            //这里,添加之后返回的user密码已经被hash过
            var a = HashLibrary.HashedPassword.New(user.PassWordHash);

            user.PassWordHash = a.Hash + a.Salt;
            await AddAsync(user);

            return(user);
        }
Ejemplo n.º 2
0
 public void ValidatePassword(string password)
 {
     validator.SetLengthBounds(8, 50);
     validator.AddCheck(EzPasswordValidator.Checks.CheckTypes.Numbers);
     validator.AddCheck(EzPasswordValidator.Checks.CheckTypes.Letters);
     if (!validator.Validate(password))
     {
         throw new _401Exception("Password is not strong enough!");
     }
 }
Ejemplo n.º 3
0
 public void Setup()
 {
     _validator = new PasswordValidator();
     _validator.AddCheck(CheckTypes.LetterRepetition);
     _check = new LetterRepetitionCheck();
 }
Ejemplo n.º 4
0
 public void WhenAddingNonExistingCheckTypeThenExceptionIsThrown() =>
 Assert.ThrowsException <ArgumentOutOfRangeException>(() => _validator.AddCheck(OutOfRangeCheckType));
 public void Setup()
 {
     _validator = new PasswordValidator();
     _validator.AddCheck(CheckTypes.NumberSequence);
     _check = new NumberSequenceCheck();
 }