public override ProtectedString Generate(PwProfile prf, CryptoRandomStream crsRandomSource) { if (prf == null) { Debug.Assert(false); } else { Debug.Assert(prf.CustomAlgorithmUuid == Convert.ToBase64String( m_uuid.UuidBytes, Base64FormattingOptions.None)); } Random keylen = new Random((int)crsRandomSource.GetRandomUInt64()); int k = keylen.Next(3, 7); return new ProtectedString(false, cockPwdGenerator(k,keylen)); }
public override ProtectedString Generate(PwProfile prf, CryptoRandomStream crsRandomSource) { Random r = new Random((int)crsRandomSource.GetRandomUInt64()); var opt = new DiceWareOptions(prf.CustomAlgorithmOptions); string result = ""; int word = 0; for (int i = 0; i < 5 * opt.WordCount; i++) { word *= 10; word += (1 + r.Next(6)); if ((i + 1) % 5 == 0 && i > 0) { result += words[word]; result += " "; word = 0; } } return new ProtectedString(true, result.Trim()); }
public override ProtectedString Generate(PwProfile prf, CryptoRandomStream crsRandomSource) { if (prf == null) Debug.Assert(false); else Debug.Assert(prf.CustomAlgorithmUuid == Convert.ToBase64String(m_uuid.UuidBytes, Base64FormattingOptions.None)); if (string.IsNullOrEmpty(settings.WordListLocation)) { System.Windows.Forms.MessageBox.Show("No word list location"); GetSettingsFromUser(); return null; } if (!System.IO.File.Exists(settings.WordListLocation)) { System.Windows.Forms.MessageBox.Show(string.Format("Word List doesn't exist at location {0}", settings.WordListLocation)); GetSettingsFromUser(); return null; } try { if (words == null) words = System.IO.File.ReadAllLines(settings.WordListLocation); StringBuilder sb = new StringBuilder(); for (int i = 0; i < settings.NumberOfWords; i++) { ulong u = crsRandomSource.GetRandomUInt64(); u %= (ulong)(words.Length - 1); if (i > 0) sb.Append(settings.Separator); string word = words[u]; if (i == 0 && word.Length > 1) word = word.Substring(0, 1).ToUpper() + word.Substring(1, word.Length - 1); sb.Append(word); } sb.Append(settings.TrailingTrash); return new ProtectedString(false, sb.ToString()); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(string.Format("Encountered this error while generating password: {0}", ex.Message)); } return null; }