p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_howto thread: Random Passwords


Message #1 by andy@a... on Fri, 23 Feb 2001 10:59:49
I did that at www.alarconespinosa.com (it's in spanish).
It's working well, since many people has registered and enter with the brand
new random password.
I suggest to allow then to change the password to an easier one,
The code I use is, which I found somewhere at www.asp101.com

<%
'To make a password
Dim NewPassword
RandomPassword 8, NewPassword
%>

<%
Function RandomPassword(PasswordLength, ReturnedPassword)

    Dim lNumberOfLowerCases
    Dim lNumberOfUpperCases
    Dim lNumberOfNumbers
    Dim l, j

    ReturnedPassword = ""
    If PasswordLength < 3 Then
        RandomPassword = False
        Exit Function
    End If

    'Get the number of digits for each type of characters
    Randomize
    'lNumberOfLowerCases = CInt((PasswordLength - 3) * Rnd) + 1
    'lNumberOfUpperCases = CInt((PasswordLength - lNumberOfLowerCases - 2) *
Rnd) + 1
    lNumberOfLowerCases = CInt((PasswordLength - 3) * Rnd) + 1
    lNumberOfUpperCases = 0
    lNumberOfNumbers = PasswordLength - lNumberOfLowerCases -
lNumberOfUpperCases



    ReturnedPassword = ""
    For l = 1 To PasswordLength
        Randomize
        j = CInt(2 * Rnd + 1)
        Select Case j
        Case 1 'Lower Case
            If lNumberOfLowerCases > 0 Then
                ReturnedPassword = ReturnedPassword & Chr(CInt(25 * Rnd) +
97)
                lNumberOfLowerCases = lNumberOfLowerCases - 1
            Else
                l = l - 1 'Re-do the loop
            End If
        Case 2 'Upper Case
            If lNumberOfUpperCases > 0 Then
                ReturnedPassword = ReturnedPassword & Chr(CInt(25 * Rnd) +
65)
                lNumberOfUpperCases = lNumberOfUpperCases - 1
            Else
                l = l - 1 'Re-do the loop
            End If
        Case 3 'Number
            If lNumberOfNumbers > 0 Then
                ReturnedPassword = ReturnedPassword & CInt(9 * Rnd)
                lNumberOfNumbers = lNumberOfNumbers - 1
            Else
                l = l - 1 'Re-do the loop
            End If
        End Select
        For j = 1 To 100
            'Give the seed some time
        Next
    Next


    RandomPassword = True
End Function
%>
<script language=JavaScript runat=Server>
function test(src) {
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return regex.test(src);
  }
</script>

-----Mensaje original-----
De: andy@a... [mailto:andy@a...]
Enviado el: viernes, 23 de febrero de 2001 11:00
Para: How To
Asunto: Random Passwords


Hi

Has anyone played with random (meaningful) password generation.

What I'm trying to do is ask the visitor for their email address and email
them a password, which they have to receive before they can continue.

Thanks

Andy Green


  Return to Index