代码
/// <summary>
/// 随机生成密码
/// </summary>
/// <param name="pwdchars">密码备选字符</param>
/// <param name="pwdlen">密码长度</param>
/// <returns>密码</returns>
public static string MakePassword(string pwdchars, int pwdlen)
{
string tmpstr = "";
int iRandNum;
Random rnd = new Random();
for (int i = 0; i <pwdlen ; i++)
{
iRandNum = rnd.Next(pwdchars.Length);
tmpstr += pwdchars[iRandNum];
}
return tmpstr;
}
/// 随机生成密码
/// </summary>
/// <param name="pwdchars">密码备选字符</param>
/// <param name="pwdlen">密码长度</param>
/// <returns>密码</returns>
public static string MakePassword(string pwdchars, int pwdlen)
{
string tmpstr = "";
int iRandNum;
Random rnd = new Random();
for (int i = 0; i <pwdlen ; i++)
{
iRandNum = rnd.Next(pwdchars.Length);
tmpstr += pwdchars[iRandNum];
}
return tmpstr;
}