-
User authentication
I want to design a simple authentication system using usernames and passwords stored in a table called members.
I have a login form...if there username and password is in the table I'm able to open another form for them to update their member information. My login form opens up the maintenance form that is bound to a query (user_lookup) that looks up the username and password.
If their username or password is not in the table, I want to be able to send them to a form to register/signup...how can I do this? I assume I need to evaluate whether or not the username in the user_loop query results is null and then open the form I want. I'm not sure how to do this...macro? code?
Thanks
-
Create a VB module with this function:
Function checkLogin(username, password) As Boolean
Dim myDB As Database
Dim myRS As Recordset
Dim sCmd As String
Set myDB = CurrentDb()
sCmd = "SELECT memberID FROM members Where username = '" & username & "' AND password = '" & password & "'"
Set myRS = myDB.OpenRecordset(sCmd)
checkLogin = Not myRS.EOF
myRS.Close
Set myRS = Nothing
Set myDB = Nothing
End Function
Taken you have a login form with two fields and a button as follows:
txtUserName
txtPassword
btnLogin
You put the following code into the btnLogin_onClick event:
Dim bLoginSuccess as Boolean
Dim iAction as Integer
bLoginSuccess = checklogin (txtUserName, txtPassword)
If bLoginSuccess Then
' open the maintenace screen
Else
iAction = MsgBox("Login Failed! Try again?", vbOKCancel)
End If
Use the return code of the Msgbox to decide what to do next. E.g. LEt the user register or quit the application or try again.
You could also extend the function to return not only true / false but a return code which indicates the cause of the failure (e.g. unknown user, wrong password).
Last edited by andi_g69; 02-09-2003 at 05:00 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|