Results 1 to 7 of 7

Thread: Login UserName & Password

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Location
    Arkansas
    Posts
    28

    Unhappy

    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.

  2. #2
    New Member
    Join Date
    Oct 2000
    Posts
    3
    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

  3. #3
    Addicted Member
    Join Date
    Feb 2000
    Posts
    224
    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

    Code:
    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.
    If you can't pronounce my name, call me GURU

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Location
    Arkansas
    Posts
    28
    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.

  5. #5
    Lively Member
    Join Date
    Jul 2000
    Location
    Brunei
    Posts
    100
    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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Location
    Arkansas
    Posts
    28

    Angry

    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


  7. #7
    Lively Member
    Join Date
    Jul 2000
    Location
    Brunei
    Posts
    100
    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]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width