It is easy to implement asp.net to generate random password, the following code gives the complete implementation method:
Copy Code code as follows:
Publicstaticstringmakepassword (Stringpwdchars,intpwdlen)
{
Stringtmpstr= "";
Intirandnum;
Randomrnd=newrandom ();
for (inti=0; i{
Irandnum=rnd. Next (Pwdchars. Length);
Tmpstr+=pwdchars[irandnum];
}
RETURNTMPSTR;
}
Control source, talk about the specific ideas:
Method Makepassword accepts two parameters, the Pwdchars parameter specifies which characters can be used by the generated random cipher string, and Pwdlen specifies the length of the generated random cipher string. With these two parameters, by calling the Next () method of the Random class, you first get an integer greater than or equal to 0 and less than the pwdchars length, taking the number as the index value, randomly taking the characters from the available strings, specifying the length of the password as the number of loops, and then connecting the acquired Finally, we get the random cipher string that I need.
The code calls the Makepassword () method to obtain a random string with a length of 10 and a range of characters with uppercase and lowercase letters and numbers.
String randomchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string password = Makepassword (Randomchars, 10); Above is asp.net generate random password.