async Task UserDetailViewModel_PropertyChangedAsync(object sender, PropertyChangedEventArgs e) { Console.WriteLine("Property " + e.PropertyName + " changed"); switch (e.PropertyName) { case "Email": { EmailErrors.Clear(); var Errors = await GetEmailErrors(Email); EmailErrors.AddRange <string>(Errors); useEmailErrors?.Invoke(Errors); } break; case "Password": { PasswordErrors.Clear(); var Errors = GetPasswordErrors(Password); PasswordErrors.AddRange <string>(Errors); usePasswordErrors?.Invoke(Errors); } break; case "ConfirmPassword": { ConfirmPasswordErrors.Clear(); var Errors = GetConfirmPasswordErrors(Password, ConfirmPassword); ConfirmPasswordErrors.AddRange <string>(Errors); useConfirmPasswordErrors?.Invoke(Errors); } break; } }
/// <summary> /// Checks a password for "good enough". /// </summary> /// <param name="pwd">Password to check.</param> /// <param name="error">The error of the password, if return value is false.</param> /// <returns>true, if password is good</returns> public static bool CheckPassword(string pwd, out PasswordErrors error) { /** * A password is "Good enough" if: * It is at least SufficientLength characters long * OR * It is at least MinLength characters long AND it has * at least one uppercase and one lowercase and one (digit or other). * * A future enhancement of this might be to calculate the Shannon Entropy * in combination with a minimum password length. * http://rosettacode.org/wiki/Entropy */ error = PasswordErrors.None; const int sufficientLength = 12; const int minLength = 8; var length = pwd.Length; if (length >= sufficientLength) { return(true); } if (length < minLength) { error = PasswordErrors.PasswordTooShort; return(false); } // check for at least one uppercase and lowercase and one (digit or other) bool hasUc = false, hasLc = false, hasDigit = false, hasOther = false; foreach (var c in pwd) { if (char.IsLower(c)) { hasLc = true; } else if (char.IsUpper(c)) { hasUc = true; } else if (char.IsDigit(c)) { hasDigit = true; } else { hasOther = true; } } if (hasUc && hasLc && (hasDigit || hasOther)) { return(true); } error = PasswordErrors.PoorPassword; return(false); }
public PasswordComplexityException(PasswordErrors complexityRule, int errorParameter, string validationError) : base(validationError) { ComplexityRule = complexityRule; ErrorParameter = errorParameter; ErrorCategory = validationError; }
public PasswordHistoryException(PasswordErrors historyRule, string validationError) : base(validationError ?? "Password history rule violated") { HistoryRule = historyRule; ValidationError = validationError; }