ASP + SQL randomly generate user passwords

Source: Internet
Author: User
Note: You can randomly generate a password and then email it to the registered user. You can confirm that the user's email is correct. Automatically Generated passwords are often more secure. At the same time, you can filter invalid users.

Save the following code as a random. asp file:

Quote: <%
Sub strrandomize (strseed)
Dim I, nseed
Nseed = clng (0)
For I = 1 to Len (strseed)
Nseed = nseed XOR (256 * (I-1) mod 4) * ASCB (mid (strseed, I, 1 ))))
Next
Randomize nseed
End sub

Function generatepassword (nlength)
Dim I, bmadeconsonant, C, nrnd
Const strdoubleconsonants = "bdfglmnpst"
Const strconsonants = "bcdfghklmnpqrstv"
Const strvocal = "aeiou"
Generatepassword = ""
Bmadeconsonant = false
For I = 0 to nlength
Nrnd = RND
If generatepassword <> "" And (bmadeconsonant <> true) and (nrnd <0.15) then
C = mid (strdoubleconsonants, INT (LEN (strdoubleconsonants) * RND + 1), 1)
C = C & C
I = I + 1
Bmadeconsonant = true
Else
If (bmadeconsonant <> true) and (nrnd <0.95) then
C = mid (strconsonants, INT (LEN (strconsonants) * RND + 1), 1)
Bmadeconsonant = true
Else
C = mid (strvocal, INT (LEN (strvocal) * RND + 1), 1)
Bmadeconsonant = false
End if
End if
Generatepassword = generatepassword & C
Next

If Len (generatepassword)> nlength then
Generatepassword = left (generatepassword, nlength)
End if
End Function
%>

Then you can call the above Code in your target program to automatically generate the password: (just an example, you can paste them into a test. ASP file, and then run test. ASP)

Quote: <! -- Include file = "random. asp" -->
<%
'Generate a six-digit password
Strrandomize CSTR (now) & CSTR (RND)
Response. Write generatepassword (6)
%>

<%
'Generate an 8-bit password
Strrandomize CSTR (now) & CSTR (RND)
Response. Write generatepassword (8)
%>

<%
'Generate a 10-bit password
Strrandomize CSTR (now) & CSTR (RND)
Response. Write generatepassword (10)
%>

<%
'Generate 1000 passwords
Dim t, T2
For t = 1 to 500
For t2 = 1 to 661
Strrandomize CSTR (now) & CSTR (RND)
Next
Strrandomize CSTR (now) & CSTR (RND)
Response. Write generatepassword (6)
Response. Write "<br>"
Next
%>

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.