예제 #1
0
 public void CheckPasswordLength_ShortAcceptable()
 {
     Assert.AreEqual(true, ps.CheckPasswordLength(new string('a', 12)));
 }
예제 #2
0
파일: UserManager.cs 프로젝트: cf2080/SSO
        public User CreateUser(
            string email,
            string password,
            DateTime dob,
            string city,
            string state,
            string country,
            string securityQ1,
            string securityQ1Answer,
            string securityQ2,
            string securityQ2Answer,
            string securityQ3,
            string securityQ3Answer)
        {
            new System.Net.Mail.MailAddress(email);

            DateTime today18YearsAgo = DateTime.Now.AddYears(-18);

            if (dob > today18YearsAgo)
            {
                throw new InvalidDobException("Date of birth less than 18 years ago");
            }

            if (!_passwordService.CheckPasswordLength(password))
            {
                throw new PasswordInvalidException("Password is too short");
            }

            int pwnedCount = _passwordService.CheckPasswordPwned(password);

            if (pwnedCount > 0)
            {
                throw new PasswordPwnedException("Password has been pwned");
            }

            byte[] salt = _passwordService.GenerateSalt();
            string hash = _passwordService.HashPassword(password, salt);

            User user = new User
            {
                Email        = email,
                PasswordHash = hash,
                PasswordSalt = salt,

                DateOfBirth = dob,
                City        = city,
                State       = state,
                Country     = country,

                SecurityQ1       = securityQ1,
                SecurityQ1Answer = securityQ1Answer,
                SecurityQ2       = securityQ2,
                SecurityQ2Answer = securityQ2Answer,
                SecurityQ3       = securityQ3,
                SecurityQ3Answer = securityQ3Answer,
                UpdatedAt        = DateTime.UtcNow,
                CreatedAt        = DateTime.UtcNow
            };

            return(_userService.CreateUser(user));
        }