Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generate random username and passwords 3

Status
Not open for further replies.

nim180

IS-IT--Management
Aug 11, 2005
161
AU
Hey everyone,

Is it possible to generate 20 random usernames and passwords when the administrator clicks on a button. For example i have a custom password form which the administrator uses to login but all other users must use random usernames and passwords which need to be generated at the start of each day when the database is opened.

So when the administrator logs in he will click on a button which generates these usernames and passwords and prints them out. These usernames/Passwords are then used by other users to login......sorry if i didnt explain this properly. Any help is greatly appreciated.

Thanks,
Nim
 
Like alvechurchdata's suggestion for password generation.

To be able to login, such usernames/passwords will need to be integrated into the security system for the database.

If this is purely stored within tables within the database, then its a matter of storing them within a table and then giving the new authentication information to the users.

If, however, these are to be usernames/password with Access security, you will need to manipulate the security settings through VBA to add the new ones into the workgroup information file.

Of course, the "generate" function may also have to expire any previous usernames that existed from the last run (unless you store an expiry date alongside the account with the username) - and of course the usernames would have to be guaranteed to be unique; I trust that within this application there is no requirements for auditing over a long period.

John
 
If you are going to store usernames/passwords, then consider a Public array to store them for the session. Unless the database is encrypted, keeping them in a table will sort of defeat the security purpose.

Cheers,
Bill
 
Hi everyone thanks for your replies, well the random usernames/passwords can be saved in a simple table which my custom password form can be linked to the table so all the generated usernames/passwords can be used by different users, but how can i generate this information? Im not sure how to go about doing that!
 
Write a VBA function that loops through the function, 20 times and writes the results into a table. IF your application's authentication mechanism looks at that table, as does a report to display onscreen/print them out will be fine.

For the usernames you need to ensure that this is unique, so a lookup against the username or loginid field to check for 0 values matching is a necessity.

John
 
How are ya nim180 . . .

Note: the link provided by [blue]alvechurchdata[/blue] is a good one ... however there's a big flaw in the code on the following line:
Code:
[blue]strRtn = strRtn & Mid(strAvailableChars, Int((Len(strAvailableChars) , 1 * 1) * Rnd * 1), 1)[/blue]
I cleaned up the code and made it [blue]easier to read[/blue]. Note: credit for the function still goes to [blue]spyka[/blue].

The test table I used has the following structure:

[tt][blue]tblRndUsr
---------

UsrID as autonumber
UsrName as string [green]'random user name[/green]
RndUsr as string [green]'random Password[/green]
RndPWD as string[/blue][/tt]

In the code which follows I included variable character count (current lengths are from 5 to 10 characters), which are randomly chosen. Length limits can be changed by you in code ... so here we go ... In a module in the modules, copy/paste the following ([blue]you[/blue] substitute proper names in [purple]purple[/purple]):
Code:
[blue]Public Sub GenLogin()
   Dim db As DAO.Database, rst As DAO.Recordset
   Dim Nam As String, PWD As String
   Dim NamChrCnt As Integer, PWDChrCnt As Integer
   Const LoChrCnt As Integer = 5, HiChrCnt As Integer = 10 [green]'Character count limits[/green]
   
   Set db = CurrentDb
   Set rst = db.OpenRecordset("[purple][B][I]tblRndUsr[/I][/B][/purple]", dbOpenDynaset)
   
   If Not rst.BOF Then
      Do Until rst.EOF
         NamChrCnt = Int((HiChrCnt - LoChrCnt + 1) * Rnd) + LoChrCnt
         Nam = GenPWD(NamChrCnt, True, True, True, True)
         
         PWDChrCnt = Int((HiChrCnt - LoChrCnt + 1) * Rnd) + LoChrCnt
         PWD = GenPWD(PWDChrCnt, True, True, True, True)
         
         With rst
            .Edit
            ![purple][B][I]RndUsr[/I][/B][/purple] = Nam
            ![purple][B][I]RndPwd[/I][/B][/purple] = PWD
            .Update
            .MoveNext
         End With
         
         Nam = ""
         PWD = ""
      Loop
   End If
   
End Sub

Public Function GenPWD(Optional PassLen As Integer = 10, _
                       Optional includeUpperCase As Boolean = False, _
                       Optional includeNumbers As Boolean = False, _
                       Optional includeSymbols As Boolean = False, _
                       Optional includeSimilarChars As Boolean = False) As String

On Error GoTo GotErr

   Dim Pak As String, Build As String, x As Integer

   Pak = "abcdefghijkmnpqrstuvwxyz"
   If includeSimilarChars Then
      Pak = Pak & "lo"
   End If

   If includeUpperCase Then
      Pak = Pak & "ABCDEFGHJKLMNPQRSTUVWXYZ"
      If includeSimilarChars Then
         Pak = Pak & "IO"
      End If
   End If

   If includeNumbers Then
      Pak = Pak & "23456789"
      If includeSimilarChars Then
         Pak = Pak & "10"
      End If
   End If

   If includeSymbols Then
      Pak = Pak & "$%^&*()-=+[]{};'#:@~<>?,./\"
      If includeSimilarChars Then
         Pak = Pak & "!"
      End If
   End If

   Randomize
   Build = ""

   For x = 1 To PassLen
      Build = Build & Mid(Pak, Int(Len(Pak) * Rnd) + 1, 1)
   Next x

   GenPWD = Build

On Error GoTo 0

Exit Function

GotErr:

   MsgBox Err.Description & " (" & Err.Number & ")"
   GenPWD = ""
   Exit Function
   Resume Next

End Function[/blue]
Perform your testing!

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Sorry its been nearly 2 years since i created my last Access database and have forgotten alot of things. I have created the module but how do i call the module on my button so when the button is clicked the usernames/passwords are created and saved into the desired table. Thanks
 
You don't call the module, you call the sub named - in the case of TheAceMan1's code it is GenLogin.

The only time you use the name of a module in creating it is with a class module, but that is not relevant to this.

John
 
nim180 . . .

Correcting an error:

[tt][blue]tblRndUsr
---------

UsrID as autonumber
UsrName as string [green]'random user name[/green]
RndUsr as string [green]'random Password[/green]
RndPWD as string[/blue]

should be:

[blue]tblRndUsr
---------

UsrID as autonumber
UsrName as string
RndUsr as string [green]'random UsrNames[/green]
RndPWD as string [green]'random Passwords[/green][/blue][/tt]

[ol][li]For testing ... make the table I provided with the exact table/field names and assign some UsrNames.[/li]
[li]In the [blue]On Click[/blue] event of your button, copy/paste the following:
Code:
[blue]   Call GenLogin[/blue]
[/li]
[li]Save then open the form.[/li]
[li]When you hit the button each record in the table is assigned a new RndUsr & RndPWD. Close the form then open the table to check this.[/li][/ol]
[blue]your thoughts/ . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Worked perfectly, thank very much for your help everyone.

Nim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top