예제 #1
0
        /// <summary>
        /// Perform checks on the supplied password to ensure it meets:
        /// - Between 6 and 16 characters
        /// - At least one capital letter
        /// - At least 2 numbers
        /// - At least 1 special character
        /// </summary>
        /// <param name="password">unhashed password to validate</param>
        private void ValidatePassword(string password)
        {
            var len = password.Length;

            if (len <= 5 || len >= 15)
            {
                ThrowWithCode(AuthException.PW_LENGTH);
            }
            if (!StringValidator.HasNumber(password))
            {
                ThrowWithCode(AuthException.PW_SHOULD_CONTAIN_NUMBERS);
            }
            if (!StringValidator.HasUppercase(password))
            {
                ThrowWithCode(AuthException.PW_SHOULD_HAVE_UPPERCASE);
            }
            if (!StringValidator.HasLowercase(password))
            {
                ThrowWithCode(AuthException.PW_SHOULD_HAVE_LOWERCASE);
            }
            if (!StringValidator.HasSymbols(password))
            {
                ThrowWithCode(AuthException.PW_SHOULD_HAVE_SYMBOLS);
            }
        }