av8tordude
07-28-2011, 05:52 PM
Hi Everyone, Can someone assist with inserting 3 dashes (in random position) of the password created.
Thanks
e.g.
jOov-PkA-5YXwF-eU1x
ZmFE-A5o2-TiwU-ziYa
E2-zz4ZX-cBfbXM-p2b
Sub PasswordGenerator()
Dim Password As String
Dim PasswordLength As Byte
Dim LC As Byte 'Loop Counter
Dim strRndmChr As String
Dim LAC As Byte 'Lowest Ascii Character
Dim HAC As Byte 'Highest Ascii Character
Dim UseSymbolics As Boolean
Dim HasSymbolics As Boolean
Dim RandomNumber As Byte
'Set parameters.
PasswordLength = 16
LAC = Asc("0")
HAC = Asc("z")
UseSymbolics = False
Randomize
For LC = 1 To PasswordLength
'To produce random integers in a given range, use this formula:
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Do
RandomNumber = Int((HAC - LAC + 1) * Rnd + LAC)
strRndmChr = Chr(RandomNumber)
HasSymbolics = CheckSymbolics(RandomNumber)
Loop Until UseSymbolics = True Or HasSymbolics = False
Password = Password & strRndmChr
Next LC
Range("D2").Value = Password
'ActiveCell = Password
End Sub
Private Function CheckSymbolics(RandomNumber As Byte)
If (RandomNumber >= 33 And RandomNumber <= 47) Or _
(RandomNumber >= 58 And RandomNumber <= 64) Or _
(RandomNumber >= 91 And RandomNumber <= 96) Or _
(RandomNumber >= 123 And RandomNumber <= 126) Then _
CheckSymbolics = True Else: CheckSymbolics = False
End Function
Thanks
e.g.
jOov-PkA-5YXwF-eU1x
ZmFE-A5o2-TiwU-ziYa
E2-zz4ZX-cBfbXM-p2b
Sub PasswordGenerator()
Dim Password As String
Dim PasswordLength As Byte
Dim LC As Byte 'Loop Counter
Dim strRndmChr As String
Dim LAC As Byte 'Lowest Ascii Character
Dim HAC As Byte 'Highest Ascii Character
Dim UseSymbolics As Boolean
Dim HasSymbolics As Boolean
Dim RandomNumber As Byte
'Set parameters.
PasswordLength = 16
LAC = Asc("0")
HAC = Asc("z")
UseSymbolics = False
Randomize
For LC = 1 To PasswordLength
'To produce random integers in a given range, use this formula:
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Do
RandomNumber = Int((HAC - LAC + 1) * Rnd + LAC)
strRndmChr = Chr(RandomNumber)
HasSymbolics = CheckSymbolics(RandomNumber)
Loop Until UseSymbolics = True Or HasSymbolics = False
Password = Password & strRndmChr
Next LC
Range("D2").Value = Password
'ActiveCell = Password
End Sub
Private Function CheckSymbolics(RandomNumber As Byte)
If (RandomNumber >= 33 And RandomNumber <= 47) Or _
(RandomNumber >= 58 And RandomNumber <= 64) Or _
(RandomNumber >= 91 And RandomNumber <= 96) Or _
(RandomNumber >= 123 And RandomNumber <= 126) Then _
CheckSymbolics = True Else: CheckSymbolics = False
End Function