password generating

xcao

Registered User.
Local time
Today, 16:18
Joined
Nov 25, 2003
Messages
40
How can I module that generates password.

The passowrd should be 8 characters long, including small
and capital letter and numbers?

Thanks in advance
 
Try this.
PHP:
Dim ChooseType As Integer
Dim UpperLower As Integer
Dim pwStore As String
Dim pwLength As Integer
Dim pw As String

'Length of password'
pwLength = 8

For i = 1 To pwLength

ChooseType = Round(Rnd)

If ChooseType = 1 Then
    'Number'
    pwStore = Chr(Int((57 - 48 + 1) * Rnd + 48))
Else
    'Alphabet'
    UpperLower = Round(Rnd)
    If UpperLower = 1 Then
        'Upper Case'
        pwStore = UCase$(Chr(Int((90 - 65 + 1) * Rnd + 65)))
    Else
        'Lower Case'
        pwStore = LCase$(Chr(Int((90 - 65 + 1) * Rnd + 65)))
    End If
End If

pw = pw & pwStore

Next i

MsgBox "Password generated = " & pw

Edit # 1: Removed the line Randomize(0) before ChooseType = Round(Rnd). It seemed to make the code repeat ater awhile???
:confused:
Try the code with pwLength =400 (with and without the Randomize(0) line) and you'll see what I mean.
But I've read that one should call Randomize(0) before calling Rnd.

Edit # 2: Just realized that I don'thaev to use UCase or LCase.
PHP:
'Upper Case'
pwStore = Chr(Int((90 - 65 + 1) * Rnd + 65))

'Lower Case'
pwStore = Chr(Int((122 - 97 + 1) * Rnd + 97))
 
Last edited:
Thank you very much.

I wonder if the password will have a repetition.

Do I need to write code to loop through the password table to check if it is the same with the new generated password, if same, then run generate password again.

Thanks
 
xcao said:
I wonder if the password will have a repetition.

Do I need to write code to loop through the password table to check if it is the same with the new generated password, if same, then run generate password again.
I think that is a good idea, just to be on the safe side.
:)
 

Users who are viewing this thread

Back
Top Bottom