Creating a login process in MS Access 2000-2003

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • meLady
    New Member
    • Apr 2007
    • 27

    Creating a login process in MS Access 2000-2003

    Hello,

    I have a table which called "users" and it has two fields "username" and "password".

    Also, I have a form that called "User Login", and it has as following:
    -txtUsername
    -txtPassword
    -btnEnter

    So, I would like to know how the code goes for this type of idea. I want the user to insert his/her username and password in the login form and then when pressing the Enter button, the system will check and varify the username and password from the users table.

    as usual if it wrong ... the error message will be displayed and if it right the next form will be opened ...

    I will be more delighted if you could help me in providing the right solutions for my queries which is really new to me (^_^)

    I am waiting for your kindly answer.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by meLady
    Hello,

    I have a table which called "users" and it has two fields "username" and "password".

    Also, I have a form that called "User Login", and it has as following:
    -txtUsername
    -txtPassword
    -btnEnter

    So, I would like to know how the code goes for this type of idea. I want the user to insert his/her username and password in the login form and then when pressing the Enter button, the system will check and varify the username and password from the users table.

    as usual if it wrong ... the error message will be displayed and if it right the next form will be opened ...

    I will be more delighted if you could help me in providing the right solutions for my queries which is really new to me (^_^)

    I am waiting for your kindly answer.
    In the Click() Event of btnEntered:
    Code:
    'Make sure byou have both a UserName and Password entered
    If IsNull(Me![txtUserName]) Or IsNull(Me![txtPassword]) Then Exit Sub
    
    If DLookup("username", "users", "username='" & txtUserName & "'") <> "" Then
      'we have a valid UserName, just need a valid UserName/Password combination
      If DLookup("password", "users", "username='" & txtUserName & "'") = Me![txtPassword] Then
        'if you get here, User provided a valid UserName/Password 
        'combination as defined in the users Table
        'GOOD TO GO!!!
      Else
        MsgBox "Invalid Password for User " & Me![txtUserName], vbExclamation, "Invalid Password"
          Exit Sub
      End If
    Else
      MsgBox "Invalid User Name", vbExclamation, "Login Failure"
        Exit Sub
    End If
    NOTE: I would suggest you Index with No Duplicates the username and password Fields for obvious reasons.
    Last edited by ADezii; Apr 23 '07, 07:08 PM. Reason: Additional Info

    Comment

    • pks00
      Recognized Expert Contributor
      • Oct 2006
      • 280

      #3
      Similar code to that of ADezii but I only check the entered password. Just assume that username is right. If username is wrong then lookup to table will fail anyway.


      Just curious ADezii, I hope you dont mind me asking, Im not trying to be rude - why would u want to put a duplicate on both username and password?
      My thoughts would be no dups on username but dups index on password
      Last edited by pks00; Apr 23 '07, 07:21 PM. Reason: removed spelling mistake

      Comment

      • meLady
        New Member
        • Apr 2007
        • 27

        #4
        Hello .........

        I am confused (`~_~`) ... but I will try ... because I really need to understand the login procedures ... and then if there is any confusions I will return to you guys.

        Again thanks a lot for your contributions (^_^)

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by pks00
          Similar code to that of ADezii but I only check the entered password. Just assume that username is right. If username is wrong then lookup to table will fail anyway.


          Just curious ADezii, I hope you dont mind me asking, Im not trying to be rude - why would u want to put a duplicate on both username and password?
          My thoughts would be no dups on username but dups index on password
          Please, don't ever feel reluctant about offering additional Input on any of my suggestions. In this case I happen to agree with you, your thoughts make more sense. I just happen to prefer the idea of total uniqueness on both UserName and Password. Thanks for the input.

          Comment

          Working...