Click to See Complete Forum and Search --> : Login UserName & Password
greysquirl
Oct 4th, 2000, 11:04 AM
Access Table - [Security]
Fields in [Security] - [Username] [Password]
I used the wizard in VB to create a prog. In the wizrd it created a login screen with a username, password and two buttons; OK & Cancel.
What code can I write to make the login access the database and log users in based on their username and password. Please be very specific, I am a new user and not real familiar with the coding.
cu_333
Oct 5th, 2000, 01:29 AM
Hi
First of all I don't think that using wizards is a good way to create applications but anyway. First of all you have to create a table where you will keep all the users and their passwords. Then when a User enter his/hers User name and password you will check if he/she exists in the table and if the password is correct. It's simple but needs some lines of code
Hoping that helps you
CU
G.Kumaraguru
Oct 5th, 2000, 05:55 AM
Assuming u know How to go about it.
here is the sql statement.
Where StrUsername and StrPassword are the username and password entered by the users
sql = "select Username from Security where Username = '" & LCase(StrUsername) & "'"
sql = sql & " and Password = '" & LCase(StrPassword) & "'"
If the recordset is empty u know they have entered incorrect
login Information.
greysquirl
Oct 5th, 2000, 01:37 PM
I have that much figured out. . . .all I can't figure out is the code that makes the text boxes look up and verify the username and password from those tables.
rathi
Oct 7th, 2000, 06:59 AM
Originally posted by greysquirl
I have that much figured out. . . .all I can't figure out is the code that makes the text boxes look up and verify the username and password from those tables.
Hi there,
I got this code from this vb-world site. Here, it goes.
Private Sub CmdLogin_Click()
'On your CmdLogin_Click event of the login screen.
Select Case ValidateUser(txtUserName, txtPassword)
Case 0
MsgBox "Successful Login.", vbOKOnly + vbInformation, "Logon"
Me.Hide
frmStockEntry.Show
frmStockEntry.mnuItem.Visible = True
Case 4
MsgBox "Successful Login", vbInformation + vbOKOnly, "Logon"
Me.Hide
frmStockEntry.mnuItem.Visible = False
frmStockEntry.Show
Case 1
MsgBox "Invalid User ID.", vbInformation + vbOKOnly
txtUserName.SetFocus
Case 2
MsgBox "Invalid User Password.", vbInformation + vbOKOnly
txtPassword.SetFocus
End Select
End Sub
Private Function ValidateUser(ByVal lpUserID As String, ByVal lpUserPwd As String) As Integer
Data1.Recordset.Index = "UserID"
Data1.Recordset.Seek "=", lpUserID
If Not Data1.Recordset.NoMatch Then
If StrComp(lpUserPwd, Data1.Recordset!UserPwd, vbBinaryCompare) = 0 Then
If Data1.Recordset("Specialuser") = True Then
ValidateUser = 0
ElseIf Data1.Recordset("SpecialUser") = False Then
ValidateUser = 4
End If
Else
ValidateUser = 2
End If
Else 'if there is no match in the userid
ValidateUser = 1
End If
End Function
greysquirl
Oct 9th, 2000, 10:00 AM
OK. . .I tried using the code you sent me and here is the problem. Under the Select Case you have this "ValidateUser" thing goin on. When I start the program it gives me this error when I click on the OK button. "Compile Error. . . .Sub or Function not defined". What am I doing wrong? And what else might I need to do? Remember that this is my first program ever and I am self taught. . .obviosly not well enough, but anyways. Plaese help. Thank You.
I have a table called [Security], and in it are two fields called [Username] & [Password]. I my login screen I have Username & Password text boxes that both look to the Data1 Recorset which in turn looks to the database. I hope this helps.
Private Sub cmdCancel_Click()
End
End Sub
Private Sub CmdOK_Click()
'On your CmdOK_Click event of the login screen.
Select Case ValidateUser(txtUserName, txtPassword)
Case 0
MsgBox "Successful Login.", vbOKOnly + vbInformation, "Logon"
Me.Hide
frmMain.Show
Case 4
MsgBox "Successful Login", vbInformation + vbOKOnly, "Logon"
Me.Hide
frmMain.Show
Case 1
MsgBox "Invalid User ID.", vbInformation + vbOKOnly
txtUserName.SetFocus
Case 2
MsgBox "Invalid User Password.", vbInformation + vbOKOnly
txtPassword.SetFocus
End Select
End Sub
rathi
Oct 11th, 2000, 07:09 AM
Originally posted by greysquirl
OK. . .I tried using the code you sent me and here is the problem. Under the Select Case you have this "ValidateUser" thing goin on. When I start the program it gives me this error when I click on the OK button. "Compile Error. . . .Sub or Function not defined". What am I doing wrong? And what else might I need to do? Remember that this is my first program ever and I am self taught. . .obviosly not well enough, but anyways. Plaese help. Thank You.
I have a table called [Security], and in it are two fields called [Username] & [Password]. I my login screen I have Username & Password text boxes that both look to the Data1 Recorset which in turn looks to the database. I hope this helps.
Private Sub cmdCancel_Click()
End
End Sub
Private Sub CmdOK_Click()
'On your CmdOK_Click event of the login screen.
Select Case ValidateUser(txtUserName, txtPassword)
Case 0
MsgBox "Successful Login.", vbOKOnly + vbInformation, "Logon"
Me.Hide
frmMain.Show
Case 4
MsgBox "Successful Login", vbInformation + vbOKOnly, "Logon"
Me.Hide
frmMain.Show
Case 1
MsgBox "Invalid User ID.", vbInformation + vbOKOnly
txtUserName.SetFocus
Case 2
MsgBox "Invalid User Password.", vbInformation + vbOKOnly
txtPassword.SetFocus
End Select
End Sub
Hi there,
Did you add the ValidateUser function to your code? If not, just copy the ValidateUser function from the above mentioned code.
This validateuser function takes two arguments, one is UserName (txtUserName) another is Password (txtPassword). I have two fields in the security table, which are UserID and UserPwd. In the ValidateUser function, substitute your fields.
After adding the validateuser function, this will work.
sincerely,
Rathi.J
[Edited by rathi on 10-11-2000 at 08:13 AM]
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.