public void SetUpBeforeClassBuiltIn() { test_bism = new BuiltInStrengthMeasure(); pwentry1 = new PwEntry(null, false, false); pwentry2 = new PwEntry(null, false, false); pwentry3 = new PwEntry(null, false, false); pwentry4 = new PwEntry(null, false, false); pwentry5 = new PwEntry(null, false, false); pwentry6 = new PwEntry(null, false, false); }
public override PasswordQuality Evaluate(PwEntry entry) { string usrname = GetValue(entry, EntryDataType.UserName); string pwd = GetValue(entry, EntryDataType.Password); BuiltInStrengthMeasure bism = new BuiltInStrengthMeasure(); BasicStrengthMeasure bsm = new BasicStrengthMeasure(); int strengthA = (int)bism.Evaluate(entry); int strengthB = (int)bsm.Evaluate(entry); int strength = (int)Math.Round((decimal)(strengthA + strengthB) / 2); bool containsDictWord = false; bool containsPartOfUsrName = false; bool containsReverseUsrName = false; bool containsReversePartOfUsrName = false; string reverseUsername = Reverse(usrname); try { /* * I have put into resources with GZip compression, instead of file.(Peter Torok) * If you place it uncompressed use this: * System.IO.StringReader dict = new System.IO.StringReader(Resources.dictionary); */ System.IO.Stream resource_stream = new System.IO.MemoryStream(Resources.dictionary_gzip); System.IO.Compression.GZipStream gz_stream = new System.IO.Compression.GZipStream(resource_stream, System.IO.Compression.CompressionMode.Decompress); System.IO.StreamReader dict = new System.IO.StreamReader(gz_stream); //System.IO.FileStream fileStream = System.IO.File.OpenRead("dictionary.txt"); //System.IO.StreamReader dict = new System.IO.StreamReader(fileStream); //System.IO.StringReader dict = new System.IO.StringReader(streamReader.ReadToEnd()); //TEST //System.Windows.Forms.MessageBox.Show(dict.ReadLine()); string dictWord = null; while ((dictWord = dict.ReadLine()) != null) if (pwd.Contains(dictWord)) containsDictWord = true; } catch (Exception e) { System.Windows.Forms.MessageBox.Show("An error has occured!\nDetails: " + e.ToString()); return PasswordQuality.Error; } for (int i = 3; i < usrname.Length; i++) for (int j = 0; j < usrname.Length - i; j++) if (pwd.Contains(usrname.Substring(j, i))) containsPartOfUsrName = true; for (int i = 3; i <= reverseUsername.Length; i++) for (int j = 0; j < reverseUsername.Length - i; j++) if (pwd.Contains(reverseUsername.Substring(j, i))) containsReverseUsrName = true; for (int i = 3; i < usrname.Length; i++) for (int j = 0; j < usrname.Length - i; j++) if (pwd.Contains(Reverse(usrname.Substring(j, i)))) containsReversePartOfUsrName = true; if (pwd.Contains(usrname) || containsPartOfUsrName || containsReverseUsrName || containsReversePartOfUsrName) strength--; if (containsDictWord) strength--; if (strength < 0) strength = 0; return (PasswordQuality)strength; }
public override PasswordQuality Evaluate(PwEntry entry) { string usrname = GetValue(entry, EntryDataType.UserName); string pwd = GetValue(entry, EntryDataType.Password); BuiltInStrengthMeasure bism = new BuiltInStrengthMeasure(); BasicStrengthMeasure bsm = new BasicStrengthMeasure(); int strengthA = (int)bism.Evaluate(entry); int strengthB = (int)bsm.Evaluate(entry); int strength = (int)Math.Round((decimal)(strengthA + strengthB) / 2); bool containsDictWord = false; bool containsPartOfUsrName = false; bool containsReverseUsrName = false; bool containsReversePartOfUsrName = false; string reverseUsername = Reverse(usrname); try { /* * I have put into resources with GZip compression, instead of file.(Peter Torok) * If you place it uncompressed use this: * System.IO.StringReader dict = new System.IO.StringReader(Resources.dictionary); */ System.IO.Stream resource_stream = new System.IO.MemoryStream(Resources.dictionary_gzip); System.IO.Compression.GZipStream gz_stream = new System.IO.Compression.GZipStream(resource_stream, System.IO.Compression.CompressionMode.Decompress); System.IO.StreamReader dict = new System.IO.StreamReader(gz_stream); //System.IO.FileStream fileStream = System.IO.File.OpenRead("dictionary.txt"); //System.IO.StreamReader dict = new System.IO.StreamReader(fileStream); //System.IO.StringReader dict = new System.IO.StringReader(streamReader.ReadToEnd()); //TEST //System.Windows.Forms.MessageBox.Show(dict.ReadLine()); string dictWord = null; while ((dictWord = dict.ReadLine()) != null) { if (pwd.Contains(dictWord)) { containsDictWord = true; } } } catch (Exception e) { System.Windows.Forms.MessageBox.Show("An error has occured!\nDetails: " + e.ToString()); return(PasswordQuality.Error); } for (int i = 3; i < usrname.Length; i++) { for (int j = 0; j < usrname.Length - i; j++) { if (pwd.Contains(usrname.Substring(j, i))) { containsPartOfUsrName = true; } } } for (int i = 3; i <= reverseUsername.Length; i++) { for (int j = 0; j < reverseUsername.Length - i; j++) { if (pwd.Contains(reverseUsername.Substring(j, i))) { containsReverseUsrName = true; } } } for (int i = 3; i < usrname.Length; i++) { for (int j = 0; j < usrname.Length - i; j++) { if (pwd.Contains(Reverse(usrname.Substring(j, i)))) { containsReversePartOfUsrName = true; } } } if (pwd.Contains(usrname) || containsPartOfUsrName || containsReverseUsrName || containsReversePartOfUsrName) { strength--; } if (containsDictWord) { strength--; } if (strength < 0) { strength = 0; } return((PasswordQuality)strength); }