Access 2003
I am trying to generate unique passwords to a particular format on the "After Update" of an event.
With the help of people here I am getting new passwords in the correct format
HOWEVER
When I close the application and reopen it it starts with the same password everytime and the second generated password is always the same and so on.
So it does not seem to be actually generating Unique passwords
Here is my code
Code:
Public Function RndPass() As String
'1 Capital Letter
'2 lower case letters
'3 numbers
'1 special character
Dim passwd As String
Const specialChar = "!@#$%&*_?+"
'1 Capital Letter
passwd = Chr(Int(26 * Rnd) + Asc("A"))
'2 lower case letters
passwd = passwd + Chr(Int(26 * Rnd) + Asc("a"))
passwd = passwd + Chr(Int(26 * Rnd) + Asc("a"))
'3 numbers
passwd = passwd + Format(Int(1000 * Rnd), "000")
'1 special character
passwd = passwd + Mid(specialChar, Int(Len(specialChar) * Rnd) + 1, 1)
RndPass = passwd
End Function
Code:
Public Function UniquePass() As String
Dim passwd As String
Dim passwd2 As String
Dim i As Integer
Do
passwd = RndPass
Loop While DLookup("ComputerPassword", "tblPeople", "ComputerPassword='" & passwd & "'") > ""
'disorder password
passwd2 = ""
Do While passwd <> ""
i = Int(Len(passwd) * Rnd) + 1
passwd2 = passwd2 + Mid(passwd, i, 1)
passwd = Mid(passwd, 1, i - 1) + Mid(passwd, i + 1)
Loop
UniquePass = passwd2
End Function
Code:
Private Sub LastName_AfterUpdate()
Me.ComputerPassword.Value = UniquePass
Me.ComputerUser = LCase(Left([FirstName], 1)) & "" & LCase(Replace(Replace(Replace([LastName], "-", ""), " ", ""), "ñ", "n"))
Me.EmailPass.Value = Me.ComputerPassword.Value
Me.EmailUser = LCase(Left([FirstName], 1)) & "" & LCase(Replace(Replace(Replace([LastName], "-", ""), " ", ""), "ñ", "n"))
End Sub
Can anybody assist in tweeking my code so it does indeed generate unique passwords
tia
Dave