|
 |
asp_databases thread: generating random passwords and updating dbase fields with generated passwords
Message #1 by "Eve Ukwu" <echioma@h...> on Thu, 15 Feb 2001 03:13:43
|
|
Hi, can someone help me please.. I'm unable to get this code to work and
urgently need someone with more knowledge to cast their eye over and point
me in the right direction..
Scenario
=========
I need to look at a database and insert a password into the password field
if it is empty.
ie
mMembership No and mPassword.
GRRC-1 pass
GRCC-3
GRRC99999
You can see both 3 and 99999 are empty so the function would insert from
the random function, a password into each.
Random Function
===============
<%
Function gen_key(digits)
'Create and define array:
dim char_array(50)
char_array(0) = "0"
char_array(1) = "1"
char_array(2) = "2"
char_array(3) = "3"
char_array(4) = "4"
char_array(5) = "5"
char_array(6) = "6"
char_array(7) = "7"
char_array(8) = "8"
char_array(9) = "9"
char_array(10) = "A"
char_array(11) = "B"
char_array(12) = "C"
char_array(13) = "D"
char_array(14) = "E"
char_array(15) = "F"
char_array(16) = "G"
char_array(17) = "H"
char_array(18) = "I"
char_array(19) = "J"
char_array(20) = "K"
char_array(21) = "L"
char_array(22) = "M"
char_array(23) = "N"
char_array(24) = "O"
char_array(25) = "P"
char_array(26) = "Q"
char_array(27) = "R"
char_array(28) = "S"
char_array(29) = "T"
char_array(30) = "U"
char_array(31) = "V"
char_array(32) = "W"
char_array(33) = "X"
char_array(34) = "Y"
char_array(35) = "Z"
'Initiate randomize method for default seeding
Randomize
'Loop through and create the output based on the the variable passed
'to the function for the length of the key.
Do While len(output) < digits
num = char_array(Int((35 - 0 + 1) * Rnd + 0))
output = output + num
loop
'Set return
gen_key = output
End Function
'Write the results to the browser, currently setting a 13 digit key
response.write "<pre>" & gen_key(6) & "</pre>" & vbcrlf
%>
Much thanks in advance..
E.Ukwu
Message #2 by "Vincent Drabbe" <vincent@w...> on Thu, 15 Feb 2001 09:34:52 +0100
|
|
Hi, I read your code, and found it's messy, I just wrote a much clearer
function which will do the job (I needed this function too)
Greetings
Vincent
here it is:
<%
'this function will generate a password ..digits.. long existing of
a..z/A..Z/0..9
Function GetPassword(digits)
Dim vResult, I, myRnd
Randomize
For I = 1 to digits
myRnd = CInt(Rnd*3)
If myRnd > 2 Then
vResult = vResult & CHR( Int((90 - 66) * Rnd + 65) )
Elseif myRnd > 1 then
vResult = vResult & CHR( Int((57 - 49) * Rnd + 48) )
else
vResult = vResult & CHR( Int((122 - 98) * Rnd + 97) )
End If
Next
GetPassword = vResult
End Function
%>
----- Original Message -----
From: "Eve Ukwu" <echioma@h...>
To: "ASP Databases" <asp_databases@p...>
Sent: Thursday, February 15, 2001 3:13 AM
Subject: [asp_databases] generating random passwords and updating dbase
fields with generated passwords
> Hi, can someone help me please.. I'm unable to get this code to work and
> urgently need someone with more knowledge to cast their eye over and point
> me in the right direction..
>
> Scenario
> =========
> I need to look at a database and insert a password into the password field
> if it is empty.
>
> ie
> mMembership No and mPassword.
> GRRC-1 pass
> GRCC-3
> GRRC99999
>
> You can see both 3 and 99999 are empty so the function would insert from
> the random function, a password into each.
>
> Random Function
> ===============
> <%
> Function gen_key(digits)
> 'Create and define array:
>
> dim char_array(50)
> char_array(0) = "0"
> char_array(1) = "1"
> char_array(2) = "2"
> char_array(3) = "3"
> char_array(4) = "4"
> char_array(5) = "5"
> char_array(6) = "6"
> char_array(7) = "7"
> char_array(8) = "8"
> char_array(9) = "9"
> char_array(10) = "A"
> char_array(11) = "B"
> char_array(12) = "C"
> char_array(13) = "D"
> char_array(14) = "E"
> char_array(15) = "F"
> char_array(16) = "G"
> char_array(17) = "H"
> char_array(18) = "I"
> char_array(19) = "J"
> char_array(20) = "K"
> char_array(21) = "L"
> char_array(22) = "M"
> char_array(23) = "N"
> char_array(24) = "O"
> char_array(25) = "P"
> char_array(26) = "Q"
> char_array(27) = "R"
> char_array(28) = "S"
> char_array(29) = "T"
> char_array(30) = "U"
> char_array(31) = "V"
> char_array(32) = "W"
> char_array(33) = "X"
> char_array(34) = "Y"
> char_array(35) = "Z"
>
> 'Initiate randomize method for default seeding
> Randomize
>
> 'Loop through and create the output based on the the variable passed
> 'to the function for the length of the key.
> Do While len(output) < digits
> num = char_array(Int((35 - 0 + 1) * Rnd + 0))
> output = output + num
> loop
>
> 'Set return
>
> gen_key = output
> End Function
>
> 'Write the results to the browser, currently setting a 13 digit key
> response.write "<pre>" & gen_key(6) & "</pre>" & vbcrlf
> %>
>
> Much thanks in advance..
> E.Ukwu
>
|
|
 |