Saturday, June 25, 2011

Basic User Login Details Stored In Textfile




Basic User Login Details Stored in text file.

This is a modified version of the earlier application.

This application is written to demonstrate how login details could be stored in external text file. In practice, this method should never be used. Login details stored in text file can easily be read by computer users and hence defeat the purpose of password protection.

The function "fnVerifyLoggerAgainstTextFile()" will read the correct username and password from the textfile "AuthorizedUser.txt" that must be stored in the same folder that contains this mdb application file.

Download Microsot Access application file:



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