/// <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); } }
/// <summary> /// Perform checks on the supplied username to ensure it meets: /// - Between 3 and 16 characters /// - No symbols /// </summary> /// <param name="username">unregistered username to validate</param> private void ValidateUsername(string username) { var len = username.Length; if (len <= 2 || len >= 15) { ThrowWithCode(AuthException.USERNAME_LENGTH); } if (StringValidator.HasSymbols(username)) { ThrowWithCode(AuthException.USERNAME_SYMBOLS); } }