Friday, June 24, 2011

Basic User Login




Basic User Login

Checks user login details against hardcoded authorized user details.

______________________________________________________________

Source Code:

Option Compare Database

Private Sub cmCancel_Click()
'if user cancels, quit application
DoCmd.Quit
End Sub

Private Sub cmdOK_Click()
'check for valid input
'if textboxes are not empty, verify details
If Len(Me.txtUserName) > 0 And Len(Me.txtPassword) > 0 Then
'if verification is ok, greet user
'else, deny access
If fnVerifyLogger(Me.txtUserName, Me.txtPassword) = True Then
MsgBox "Authorised User Verified.", vbInformation, "Welcome"
Else
MsgBox "Login Failed.", vbCritical, "Login Failed"
End If
Else
'request further input
If Len(Me.txtUserName) > 0 And IsNull(Me.txtPassword) Then
MsgBox "Please enter password", vbCritical, "Login Error"
Else
If IsNull(Me.txtUserName) Then
MsgBox "Please enter username", vbCritical, "Login Error"
End If
End If
End If

End Sub

Private Function fnVerifyLogger(strInputUsername As String, strInputPassword As String) As Boolean
'hardcoded details are used just to try this form
'later can be replaced by table lookup which is a common practice
Dim strHardcodedUsername As String
Dim strHardcodedUserPassword As String

strHardcodedUsername = "user1"
strHardcodedUserPassword = "password1"

'initialize as false
fnVerifyLogger = False

If _
(strInputUsername = strHardcodedUsername) _
And _
(strInputPassword = strHardcodedUserPassword) _
Then
fnVerifyLogger = True
End If

End Function


No comments:

Post a Comment