Generate random password

With this script, you can generate a random password of a random length between 6 and 10. This script may come very handy if you need to generate random passwords let say when you want to temporarily assign a forgotten password to a user.

Scripting code

<%
dim strPassword

' call the function to generate random password
strPassword = GenerateRandomPassword ()
response.write "Random Password: " & strPassword

function GenerateRandomPassword ()
dim intPWLength, intLoop, intCharType, strPwd
Const intMinPWLength = 6
Const intMaxPWLength = 10

' Generates a random number: 6, 7, 8, 9, or 10
' this number determines the length of the password. For instance, if
' the random number is 10 then, the password length will be 10
Randomize
intPWLength = int((intMaxPWLength - intMinPWLength + 1) * Rnd + intMinPWLength)
' now depending on the length of the password (dependent on the random
' number generated above), create random chracters between a-z, A-Z, or
' or 0-9 by using a for loop
for intLoop = 1 To intPWLength
' Generates a random number: 1, 2, or 3; where
' 1 gets a lowercase letter; 2 gets uppercase character, and
' 3 gets a number between 0 and 9
Randomize
intCharType = Int((3 * Rnd) + 1)

' now check if intCharType is 1, 2, or 3
select case intCharType
case 1
' get a lowercase letter a-z inclusive
Randomize
strPwd = strPwd & CHR(Int((25 * Rnd) + 97))
case 2
' get a uppercase letter A-Z inclusive
Randomize
strPwd = strPwd & CHR(Int((25 * Rnd) + 65))
case 3
' get a number between 0 and 9 inclusive
Randomize
strPwd = strPwd & CHR(Int((9 * Rnd) + 48))
end select
next

' return password
GenerateRandomPassword = strPwd
end function
%>

Output of the above code:

Random Password: L5S5IphFG