如果你想要的东西,将为您的用户提供的东西是相对容易记住,您可以随时使用我的PronouncablePasswords
类。
我最初写这个作为一个实验,用于生成可供最终用户发音的随机密码,而不是完整的gobbledygook。当然,这会降低密码的安全性,但出于您的目的,这听起来像是足够的。
该功能只是在元音和辅音之间交替(带有一些基本的例外规则),并根据它们在英语中的出现情况对所选择的字母进行“加权”。请注意,这绝不是完美的,但它确实会“在锡上说些什么”!
代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace PronouncablePasswords
{
class PasswordGenerator
{
//string vowels = "aeiou";
//string consonants = "bcdfghjklmnprstvwxyz";
/*
The reason for the duplicate letters is to add "weighting" to certain letters to allow them more chance
of being randomly selected. This is due to the fact that certain letters in the English language are more
frequently used than others.
The breakdown of usage is as follows (from most frequent to least frequent):
1. E (7)
2. T (6)
3. A, O, N, R, I, S (5)
4. H (4)
5. D, L, F, C, M, U (3)
6. G, Y, P, W, B (2)
7. V, K, X, J, Q, Z (1)
*/
string vowels = "aaaaaeeeeeeeiiiiiooooouuu";
string consonants = "bbcccdddfffgghhhhjklllmmmnnnnnpprrrrrsssssttttttvwwxyyz";
string[] vowelafter = {"th", "ch", "sh", "qu"};
string[] consonantafter = { "oo", "ee" };
Random rnd = new Random();
public string GeneratePassword(int length)
{
string pass = "";
bool isvowel = false;
for (int i = 0; i < length; i++)
{
if (isvowel)
{
if (rnd.Next(0, 5) == 0 && i<(length-1))
{
pass += consonantafter[rnd.Next(0, consonantafter.Length)];
}
else
{
pass += vowels.Substring(rnd.Next(0, vowels.Length), 1);
}
}
else
{
if (rnd.Next(0, 5) == 0 && i<(length-1))
{
pass += vowelafter[rnd.Next(0, vowelafter.Length)];
}
else
{
pass += consonants.Substring(rnd.Next(0, consonants.Length), 1);
}
}
isvowel = !isvowel;
}
return pass;
}
}
}
您在整个问题中都提到了数字。我们是否仅限于数字,因为对于很多人来说没有容易记住数字的事情。 – 2009-10-14 04:23:14
不限于数字 – 2009-10-14 04:48:47