First, you will need to download the attached class module (clsMD5.txt) and import it into your database. This class module is the core of what we're about to go over. Thanks to Robert Hubley for writing it - you're my hero!
Next, your database needs a users table. We'll use this one as an example.
Expand|Select|Wrap|Line Numbers
- tblUsers
- Field Type
- UserID AutoNum PK
- strLastName Text
- strFirstName Text
- strMI Text
- strUserName Text (no duplicates)
- strPassword Text (encrypted)
- strPermissions Text (access permissions)
So, we have the following:
Expand|Select|Wrap|Line Numbers
- Object Name Bound To
- Form frmUserOptions tblUsers
- Text Box txtTempPassword Unbound
Expand|Select|Wrap|Line Numbers
- strPassword = DigestStrToHexStr(Me.txtTempPassword)
Now, what do you do when the user tries to log into your custom login form?
Your login form will probably follow this basic structure:
Expand|Select|Wrap|Line Numbers
- Object Name Bound To
- ---------------------------------------------------
- Form frmLogin Unbound
- Text Box txtUsername Unbound
- Text Box txtPassword Unbound
- Button cmdLogin
Expand|Select|Wrap|Line Numbers
- Private Sub cmdLogin_Click()
- Dim rs As DAO.Recordset
- Set rs = CurrentDb.OpenRecordset("SELECT UserID, strUsername, strPassword FROM tblUsers", dbOpenSnapshot)
- 'first, see if the username is valid
- rs.FindFirst "strUsername = '" & Me.txtUsername & "'"
- If rs.NoMatch Then GoTo ErrorOut
- 'next, check the password
- If rs!strPassword = DigestStrToHexStr(Me.txtPassword) Then
- DoCmd.Close
- 'open switchboard and run any other code
- End If
- Exit Sub
- 'close the app if the login was incorrect
- ErrorOut:
- MsgBox "Username/password combination is invalid." & _
- vbCrLf & vbCrLf & "Exiting application.", vbCritical
- Application.Quit
- End Sub