random password

A

Ann

I have a form with a button called generating password.
Every time there is a new client registration, we will
click the button and generate a password for the user.
But for some reason the passwords have a lot of
duplicates. I use random function, I guess there
shouldn't be duplicates, but actually not.
Any ideas about how can I avoid new password is the same
as existing passwords?
The following is the code when click the generating
password button:

Thanks in advance for any ideas
--------------
pwLength = 8

For i = 1 To pwLength
Randomize (0)
ChooseType = Round(Rnd)

If ChooseType = 1 Then
'Number'
Randomize (0)
pwStore = Chr(Int((57 - 48 + 1) * Rnd + 48))
Else
'Alphabet'
'only need Lower Case'
Randomize (0)
pwStore = Chr(Int((122 - 97 + 1) * Rnd + 97))
'End If
End If

pw = pw & pwStore

Next i

MsgBox "Password generated = " & pw

'append to tblLobUsers table username and password


username = Me.ComLobReg

DoCmd.RunSQL "Insert into UserPass (Username, Password)
Values(" & username & ", '" & pw & "')"
 
M

Martin Seelhofer

Hey Ann

1. Don't use Randomize several times, just use it once before the
for-next-loop

2. Create a separate function out of your code to generate a
random password

3. use a do-loop which does the following: call the password
creation function, check whether the password already is in the
table (using e.b. DLookup(...), if it returns the value Null, the
password is not currently in the recordset and therefore unique)
and repeat these steps if the password was already in the table...


Cheers,
Martin
 
A

Ann

Thank you very much
-----Original Message-----
Hey Ann

1. Don't use Randomize several times, just use it once before the
for-next-loop

2. Create a separate function out of your code to generate a
random password

3. use a do-loop which does the following: call the password
creation function, check whether the password already is in the
table (using e.b. DLookup(...), if it returns the value Null, the
password is not currently in the recordset and therefore unique)
and repeat these steps if the password was already in the table...


Cheers,
Martin




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top