Randomly generate user password

xiaoxiao2021-03-06  43

Because I do SP, I often generate some random passwords, send it to the user in SMS, and below is a function of randomly generating passwords! Save the following code as a Random.asp file:

<% SUB STRRANDOMIZE (STRSEED) DIM I, NSEED NSEED = CLNG (0) for i = 1 to Len (strSeed) NSEED = NSEED XOR ((256 * ((i - 1) MOD 4) * ASCB (STRSEED, I, 1))))) Next

Randomize NSEEDEND SUB

Function GeneratePassword (NLENGTH) DIM I, BMADECONSONANT, C, NRND

Const strdoubleconsonants = "bdfglmnpst" const straconsonants = "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 (Strdoucastsonants * 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 THENERATEPASSWORD = Left (GeneratePassword, NLENGTH) End ifend function%>

Then call the above code in your target program, you can implement the password automatic generation: (just an example, you can paste them into a Test.asp file, then run Test.asp)

<% 'Generating a six-digit password

Strrandomize CSTR (NOW) & CSTR (RND) Response.write GeneratePassword (6)

%>

<%

'Generates an 8-bit code StrRandomize CStr (Now) & CStr (Rnd) response.write GeneratePassword (8)%>

<% 'Generates a 10-bit code 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
"Next

%>

转载请注明原文地址:https://www.9cbs.com/read-59819.html

New Post(0)