Analysis of the random password generation function in ASP. NET

Source: Internet
Author: User

It is easy to implement the ASP. NET random password generation function. The following CodeA complete implementation method is provided: Copy codeThe Code is as follows: publicstaticstringmakepassword (stringpwdchars, intpwdlen)
{
Stringtmpstr = "";
Intirandnum;
Randomrnd = newrandom ();
For (INTI = 0; I {
Irandnum = RND. Next (pwdchars. Length );
Tmpstr + = pwdchars [irandnum];
}
Returntmpstr;
}

Let's talk about the specific ideas based on the source code:
The makepassword method accepts two parameters. The pwdchars parameter specifies which characters can be used for the generated random password string, and pwdlen specifies the length of the generated random password string. With these two parameters, call the next () method of the random class to obtain an integer greater than or equal to 0 and less than the length of pwdchars, using this number as the index value, take random characters from available strings, take the specified password length as the number of cycles, connect the obtained characters in sequence, and finally obtain the required random password string.

The Code calls the makepassword () method to obtain a random string with a length of 10 and a range of uppercase/lowercase letters and numbers.
String randomchars = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz"; string Password = makepassword (randomchars, 10); ASP. NET generates random passwords.

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.