Simple analysis of asp.net to generate random cipher function _ Practical skills

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.