Results 1 to 2 of 2
  1. #1
    SlyFox2020 is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2020
    Posts
    1

    Question Login Form (Password Help)

    I have a login in form and a user table and I have come across some problems that I don't know how to fix, I don't know if it's a really simple thing or not but I need some help. Plus this is my first database I am creating and the code is below.


    Thank You


    These are my problems:


    1. The password and username in 'tblUser' has a capital letter in it and when I go to test it, I enter both username and password without a capital letter and it still logs me in. Is there a way to have it enter exactly how it is in the table?
    2. When I was testing the login code I entered the username of the admin and the password of the user and it logged me in and brought me to the admin page ('Test 2') then, I switched it around and put the user's username and the admin's password and it brought me to the user form ('Test Form'). Both passwords work when they should only work for one user. How do I stop that from happening?

    *There was something else but I can't remember what is was. If I find it I will post again unless I found away to fix it.

    Private Sub bntOk_Click()

    Dim UserSecrity As Integer


    If IsNull(Me.txtUserName) Then
    MsgBox "Please enter User Name", vbInformation, "Password Required"
    Me.txtUserName.SetFocus


    ElseIf IsNull(Me.txtPassword) Then
    MsgBox "Please enter Password", vbInformation, "Password Required"
    Me.txtPassword.SetFocus

    Else

    If (IsNull(DLookup("UserLogin", "tblUser", "Userlogin='" & Me.txtUserName.Value & "'"))) Or _
    (IsNull(DLookup("UserPassword", "tblUser", "UserPassword='" & Me.txtPassword.Value & "'"))) Then
    MsgBox "Incorrect login or Password Details"

    Else
    usersecurity = DLookup("SecurityID", "tblUser", "UserLogin = '" & Me.txtUserName.Value & "'")
    DoCmd.Close

    If usersecurity = 1 Then
    DoCmd.OpenForm "Test2"
    Else
    DoCmd.OpenForm "Test Form"
    End If

    End If


    End If


    End Sub

    *not part of code
    Admin = 1
    User = 2

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Do you have Option Compare at the top of your code modules? Then the db is not case sensitive. I believe you'd need Option Binary - at least in the login code module.
    Please use code tags (# on forum toolbar) to make your code easier to read. I did a quick scan and see that if the user name is null, after the message box there is no Exit Sub, so code just keeps on going. More like
    Code:
    If IsNull(Me.txtUserName) Then
      MsgBox "Please enter User Name", vbInformation, "Password Required"
      Me.txtUserName.SetFocus
      Exit Sub
    End If
    These tests should be stand alone tests - not Else's (or at least do both, report that one of them is incorrect, but Exit Sub after 2nd test).

    Your IsNull test can return a value which may be incorrect - but not null - thus the login and password pass regardless of what it is. That's all I've got after a quick look because I have a question: are you sure you need a login scheme at all? The only yes reason I can think of is that multiple users share a Windows login. If not, and everyone has to log into Windows, then you can get the Windows user name, look that up in a table, and if that user name isn't there, they don't get in.

    Regardless of which approach you take, make sure people can't poke around in your tables and view/edit things that will give them permissions they should not have.
    Last edited by Micron; 02-22-2020 at 10:22 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Change password form in login system
    By Luke.F.14 in forum Access
    Replies: 3
    Last Post: 09-08-2017, 07:44 AM
  2. password login form with tags?
    By vicsaccess in forum Programming
    Replies: 6
    Last Post: 03-16-2016, 06:17 PM
  3. After Password Login Form
    By data808 in forum Access
    Replies: 13
    Last Post: 02-25-2014, 12:46 AM
  4. Login Form with Password
    By data808 in forum Programming
    Replies: 1
    Last Post: 02-12-2014, 01:06 PM
  5. Replies: 3
    Last Post: 06-22-2012, 04:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums