ChrisLayfield
Registered User.
- Local time
- Today, 09:26
- Joined
- May 11, 2010
- Messages
- 55
I have compiled this code from plenty of previous posts and it nearly does everything I need. The last part I am missing for compliance is to verify that the employee's new password does not match any of the previous 10 passwords. Does anyone have any suggestions for efficient code or a sample someplace?
Code:
'------------------------------------------------------------
' cmdSavePassword_Click
'
'------------------------------------------------------------
Private Sub cmdSavePassword_Click()
On Error GoTo cmdSavePassword_Click_Err
On Error Resume Next
Dim db As Database
Dim i As Integer
Dim iCount As Integer
Dim intUppercase As Integer
Dim intLowercase As Integer
Dim intNumeric As Integer
Dim intSpecialChar As Integer
Dim CriteriaCheck As Integer
intUppercase = 0
intLowercase = 0
intNumeric = 0
intSpecialChar = 0
CriteriaCheck = 0
iCount = 0
Set db = CurrentDb
' Test Password Length
If Nz(Me.txtPassword, "") = Nz(Me.txtConfirm, "") Then
If Len(Me.txtConfirm) < 8 Then
Me.txtPassword = Null
Me.txtConfirm = Null
Me.txtPassword.SetFocus
MsgBox "Password must be at least 8 characters", vbOKOnly
End If
End If
For i = 1 To Len(Me.txtPassword)
' Test Password for Numeric Character
If Asc(Mid(Me.txtPassword, i, 1)) >= 49 And _
Asc(Mid(Me.txtPassword, i, 1)) <= 57 Then
intNumeric = 1
End If
' Test Password for Uppercase Letter
If Asc(Mid(Me.txtPassword, i, 1)) >= 65 _
And Asc(Mid(Me.txtPassword, i, 1)) <= 90 Then
intUppercase = 1
End If
' Test Password for Lowercase Letter
If Asc(Mid(Me.txtPassword, i, 1)) >= 97 _
And Asc(Mid(Me.txtPassword, i, 1)) <= 122 Then
intLowercase = 1
End If
' Test Password for Special Characters Letter
If Asc(Mid(Me.txtPassword, i, 1)) >= 33 _
And Asc(Mid(Me.txtPassword, i, 1)) <= 47 Then
intSpecialChar = 1
ElseIf Asc(Mid(Me.txtPassword, i, 1)) >= 58 _
And Asc(Mid(Me.txtPassword, i, 1)) <= 64 Then
intSpecialChar = 1
ElseIf Asc(Mid(Me.txtPassword, i, 1)) >= 91 _
And Asc(Mid(Me.txtPassword, i, 1)) <= 96 Then
intSpecialChar = 1
ElseIf Asc(Mid(Me.txtPassword, i, 1)) >= 123 _
And Asc(Mid(Me.txtPassword, i, 1)) <= 126 Then
intSpecialChar = 1
End If
Next i
' Verify Password Meets Complexity Requirements
CriteriaCheck = intNumeric + intUppercase + intLowercase + intSpecialChar
If CriteriaCheck < 3 Then
MsgBox "The password does not meet the complexity requirements, please re-enter", vbOKOnly
Me.txtPassword = Null
Me.txtConfirm = Null
Me.txtPassword.SetFocus
Exit Sub
End If
' Verify Password is Unique (Not Used in Last 10 Changes)
'Test Password for Identical Entry
For i = 1 To (Len(Me.txtPassword) - 1)
If Asc(Mid(Me.txtConfirm, i, 1)) <> Asc(Mid(Me.txtPassword, i, 1)) Then
iCount = iCount + 1
End If
Next
' Save Password or Reject
If iCount < 1 Then
db.Execute "INSERT INTO tbl_EmployeePasswords (EmployeeID, Password, CreationDate) VALUES ('" & Forms!frmNCSLogin.cbxEmployeeID & "', '" & Forms!frmNCSPasswordChange.txtConfirm & "', Date());"
Forms!frmNCSLogin.txtPassword = Null
MsgBox "Enter new password for login"
DoCmd.Close acForm, "frmNCSPasswordChange", acSaveNo
Else
Cancel = True
Me.txtPassword = Null
Me.txtConfirm = Null
Me.txtPassword.SetFocus
MsgBox "Password doesn't match confirmation", vbOKOnly
End If
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If
cmdSavePassword_Click_Exit:
Exit Sub
cmdSavePassword_Click_Err:
MsgBox Error$
Resume cmdSavePassword_Click_Exit
iCount = 0
End Sub