private async Task UpdatePasswordStrengthIndicator(string newValue) { await Task.Yield(); string password = (string)newValue; if (!String.IsNullOrEmpty(password)) { bool isWeak = Dictionaries.Instance.IsKnownWeak(password); if (isWeak) { _strengthCheck = StrengthCheckResult.InWeakDictionary; StrengthIndicatorBackgroundColour = Color.Red; } else { double strength = SimpleRandomGenerator.GetStrength(password); _strengthCheck = strength >= _threshold ? StrengthCheckResult.OK : StrengthCheckResult.FailComplexityCheck; StrengthIndicatorBackgroundColour = _strengthCheck == StrengthCheckResult.OK ? Color.Green : Color.Orange; } } else { _strengthCheck = StrengthCheckResult.None; StrengthIndicatorBackgroundColour = Color.Gray; } OnPropertyChanged("StrengthIndicatorColWidth"); OnPropertyChanged("StrengthIndicatorText"); OnPropertyChanged("TextIsSet"); }
public static bool IsWeak(this Credential credential) { if (_weakThreshold == -1) { int recommendedCharSelection = SimpleRandomGenerator.GetTotalCharCountForSelection(SimpleRandomGenerator.CharSelection.Lowercase | SimpleRandomGenerator.CharSelection.Uppercase | SimpleRandomGenerator.CharSelection.Digits | SimpleRandomGenerator.CharSelection.Minus | SimpleRandomGenerator.CharSelection.Underline); _weakThreshold = Math.Pow(12, recommendedCharSelection); } double strength = SimpleRandomGenerator.GetStrength(credential.Password); return(strength < _weakThreshold); }