|I beefed up the code a little to make the passwords stronger. |
If the new password doesn't contain at least 2 uppercase letters, 2 lowercase letters and 2 numbers, the code will loop back and build a new one until the three criteria are met.
Of course, we still haven't dealt with the fairly common rule of not recycling passwords for some given amount of time. That could be done, but you would need to store all the old passwords for a given user and then check the new password - and date - against the list. It could be done, maybe by including a VLOOKUP in the code.
Anyway, here's the "stronger" code...
'List of characters to use for passwords
newPasswordChars = _
'Length of Password
Pass_Length = 7
'Reset check variables
NewPass = ""
numChk = 0
ucChk = 0
lcChk = 0
'Build New Password by selecting 7 ramdom characters from list
For bldPass = 1 To Pass_Length
'Randomly choose a character
nxtPassChar = Int((Len(newPasswordChars) * Rnd) + 1)
'Append it to the end of the New Password
NewPass = NewPass & Mid(newPasswordChars, nxtPassChar, 1)
'Check NewPass for 2 numbers, 2 UCase letters and 2 LCase letters
For chkPass = 1 To Pass_Length
If IsNumeric(Mid(NewPass, chkPass, 1)) Then
numChk = numChk + 1
If UCase(Mid(NewPass, chkPass, 1)) = Mid(NewPass, chkPass, 1) Then _
ucChk = ucChk + 1
If LCase(Mid(NewPass, chkPass, 1)) = Mid(NewPass, chkPass, 1) Then _
lcChk = lcChk + 1
'Build new password if any rule fails
If numChk < 2 Or ucChk < 2 Or lcChk < 2 Then GoTo ruleFailed
Selection = NewPass