生成随机密码

来源:互联网 发布:淘宝买家留言 编辑:程序博客网 时间:2024/05/16 06:05

现在的网页有时我们需要生成随机密码来发送给用户,使用户注册或者修改密码其实很简单

public string MakePassword(string pwdstr,int pwdlen)
{
string temp=”";
int RandNum;
Random rnd=new Random();
for(int i=0; i<8;i++){
RandNum=rnd.Next(pwdstr.Length);
temp+=pwdstr[RandNum];
}
return temp;
}
}

其中pwdstr是你要生成的密码中含有哪些字符,比如:

string  pwdchar=“

“!#$%^&*(abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ

“;

pwdlen是要生成密码的长度

原创粉丝点击