public static void Save(Window window, Type viewModelType) { var filename = Path.Combine(ApplicationData.Current.LocalFolder.FullName, viewModelType.FullName.GetHash() + "_Navigator"); var dictionary = new KeyRawValueDictionary(); dictionary.Add("Width", Mathc.Clamp(PersistentWindowProperties.GetWidth(window), window.MinWidth, window.MaxWidth)); dictionary.Add("Height", Mathc.Clamp(PersistentWindowProperties.GetHeight(window), window.MinHeight, window.MaxHeight)); dictionary.Add("Top", window.Top); dictionary.Add("Left", window.Left); dictionary.Add("WindowState", (int)window.WindowState); File.WriteAllBytes(filename, dictionary.Serialize()); }
public static void Load(Window window, Type viewModelType) { PersistentWindowProperties.SetHeight(window, Mathc.Clamp(window.ActualHeight, window.MinHeight, window.MaxHeight)); PersistentWindowProperties.SetWidth(window, Mathc.Clamp(window.ActualWidth, window.MinWidth, window.MaxWidth)); var filename = Path.Combine(ApplicationData.Current.LocalFolder.FullName, viewModelType.FullName.GetHash() + "_Navigator"); if (!File.Exists(filename)) { return; } var dictionary = new KeyRawValueDictionary(); dictionary.Deserialize(File.ReadAllBytes(filename)); window.WindowStartupLocation = WindowStartupLocation.Manual; window.Left = dictionary["Left"].ToDouble(); window.Top = dictionary["Top"].ToDouble(); window.Height = Math.Max(dictionary["Height"].ToDouble(), 1); window.Width = Math.Max(dictionary["Width"].ToDouble(), 1); window.WindowState = (WindowState)dictionary["WindowState"].ToInteger(); }
/// <summary> /// Checks the password's strength /// </summary> /// <param name="password">The password to check</param> /// <returns>Returns <see cref="PasswordScore"/> rating</returns> public static PasswordScore GetPasswordScore(string password) { // Origin: http://social.msdn.microsoft.com/Forums/vstudio/en-US/5e3f27d2-49af-410a-85a2-3c47e3f77fb1/how-to-check-for-password-strength if (string.IsNullOrEmpty(password)) { return(PasswordScore.Blank); } int score = 1; if (password.Length < 4) { return(PasswordScore.VeryWeak); } if (password.Length >= 8) { score++; } if (password.Length >= 12) { score++; } // If 90% of the password are numbers then lower the score if (Mathc.ValueOf(Regex.Match(password, @"[0-9]+(\.[0-9][0-9]?)?").Length, password.Length, 100) > 90) { score--; } // At least 4 of the chars should be numbers else if (Regex.Match(password, @"[0-9]+(\.[0-9][0-9]?)?").Length > 4) { score++; } // If 99% of the password are letters then lower the score if (Mathc.ValueOf(Regex.Match(password, @"^(?=.*[a-z])(?=.*[A-Z]).+$").Length, password.Length, 100) == 99) { score--; } else if (Regex.IsMatch(password, @"^(?=.*[a-z])(?=.*[A-Z]).+$")) { score++; } if (Regex.IsMatch(password, @"[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]")) { score++; } if (string.Equals(password, "password", StringComparison.CurrentCultureIgnoreCase) || string.Equals(password, "p4ssw0rd", StringComparison.CurrentCultureIgnoreCase) || string.Equals(password, "p455w0rd", StringComparison.CurrentCultureIgnoreCase)) { score = 1; } if (password.Distinct(new DynamicEqualityComparer <char>((a, b) => a == b)).Count() == 1) { score = score - 2; } return((PasswordScore)Mathc.Clamp(score, 1, 5)); }