code to generate password

  • Thread starter Thread starter Ann
  • Start date Start date
A

Ann

how can I write a module that generates password.

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

Thanks in advance
 
Hi,
Here's a simple routine. You can try changing the the numbers to acheive
different characters.

Function Default() As String
'generates four random letters and four random numbers
Randomize
n1 = Int(10 * Rnd + 48)
n2 = Int(10 * Rnd + 48)
n3 = Int(10 * Rnd + 48)
n4 = Int(10 * Rnd + 48)

a1 = Int(26 * Rnd + 97)
a2 = Int(26 * Rnd + 97)
a3 = Int(26 * Rnd + 97)
a4 = Int(26 * Rnd + 97)

Default = Chr$(a1) & Chr$(a2) & Chr$(a3) & Chr$(a4) & Chr$(n1) & Chr$(n2) &
Chr$(n3) & Chr$(n4)
End Function

Basically, numbers start at ascii 48 and lowercase letters start at 97.
Try changing this line:
a1 = Int(26 * Rnd + 97)
To
a1 = Int(26 * Rnd + 48)

You'll see that you get an intersting assortment of characters. Locate an
ASCII table to see the possibilities.
 
Back
Top