用ASCII的方法产生随机用户名或密码
2007-06-02 08:55
260 查看
/// <summary>
/// 此函数将产生12~20位的随机用户名
/// </summary>
/// <param name="length">输入12-20之间的数字</param>
/// <returns>此函数将产生12~20位的随机用户名,返回string类型</returns>
public void GetRandomString(int length)
{
Random rd = new Random();
byte[] str = new byte[length];
int i;
for (i = 0; i < length; i++)
{
int a = 0;
while (!((a >= 48 && a <= 57) || (a >= 97 && a <= 122)))
{
a = rd.Next(48, 122);
}
str[i] = (byte)a;
}
string username = new string(UnicodeEncoding.ASCII.GetChars(str));
this.register = username;
}
/// 此函数将产生12~20位的随机用户名
/// </summary>
/// <param name="length">输入12-20之间的数字</param>
/// <returns>此函数将产生12~20位的随机用户名,返回string类型</returns>
public void GetRandomString(int length)
{
Random rd = new Random();
byte[] str = new byte[length];
int i;
for (i = 0; i < length; i++)
{
int a = 0;
while (!((a >= 48 && a <= 57) || (a >= 97 && a <= 122)))
{
a = rd.Next(48, 122);
}
str[i] = (byte)a;
}
string username = new string(UnicodeEncoding.ASCII.GetChars(str));
this.register = username;
}
相关文章推荐
- Linux下产生随机密码的7种方法
- Linux下产生10位随机密码几种方法
- Linux下产生随机密码方法
- 产生随机密码10方法
- Python编程生成随机用户名及密码的方法示例
- python生成随机用户名及密码方法
- Linux下产生随机密码10方法
- 一个还不错的产生随机密码的方法
- Linux下产生随机密码10方法
- Linux下产生随机密码10方法
- 网络摘抄了一个还不错的产生随机密码的方法
- github提交代码避免输入用户名和密码的方法总结
- xcode 编译程序运行,总是提示输入用户名和密码的解决方法
- python 利用random的shuffle洗牌方法生产1个12位数的随机密码
- Ubuntu设置Firefox代理避免频繁输入代理用户名,密码的方法
- 验证码中随机汉字的产生方法
- php生成随机密码的几种方法
- 杀软EAV/ESS不用“用户名密码”就能更新的方法【各版、6.0.308依然可用】
- Git 保存用户名和密码方法
- 有没有有效及简便的方法来防止浏览器记住用户名及密码?