Page 1 of 5 123 ... LastLast
Results 1 to 15 of 71
  1. #1
    Join Date
    May 2008
    Location
    London, UK
    Posts
    46

    Question Unanswered: Password Protected Login Form w/user permisions

    Hello All, I'm currently looking for some guidance on creating a user login form which will open a different switchboard depending on a value attached to the user's record in a table.

    I have created a table called "tblAuthorisedUsers" which as 6 columns;
    • "ID" -Autonumber/primary key
    • "Name" - Full Name eg. Mike Smith
    • "Postion" - Job title
    • "Username" - eg. msmith
    • "Password" - *****
    • "AccessLevel" - "1" = admin user, "2" = general user

    I am hoping to implement something that will obviously check the user name and password as usual and then open a different form depending on the value of "AccessLevel", I intend to make an admin switch board and a general user switchboard to give the option of altering user accounts and enabling the shift key.

    The table is used elsewhere in the database, hence the "Name" & "Position" columns, if you feel this is an issue I can alter it quite easily without effecting anything too much!

    I have quite a headache after working on this db all day and I was hoping someone will take pity on me and stear me in the right direction! I have done several searches but have yet to come across anything that does what I want (and I can understand!).

    I am relatively new to Access, so please excuse me if I ask too many questions! (I'm using Access 2003 if that helps.)

    Any help you can offer will be greatly appreciated!

    Thanks very much! Regards,

    Mike

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Create a dialog form to prompt for the username and password. When the user clicks ok, it looks up in the table to see if the username/password combination is right. If the password is right, then act according to the AccessLevel and do whatever you want, open a specific "switchboard" or have your switchboard modify itself..... This all seems like I am just re-iterating what you want to achieve, but I don't know how much of a "steer" you need,... I guess it might get you started? Where have you gotten stuck?

    You should also do a search around the place, there are some recent topics here which are all about Access security and there are some alternatives you may not have considered, such as the ability to pull the Windows Username from the system to determine security levels.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Jun 2008
    Posts
    163
    Hmm, in this line of thinking, how do I properly string two lines of if conditions?

    Will this work:
    IIF("[UserTable.username]=[form!username]" AND "[UserTable.password]=[form!password]", [form!accept] "yes", [form!accept] "no")
    ..I'm asking as well since I need something like this too.

  4. #4
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Depends on how you've setup your login form. Mine has a cboUsername and txtPassword controls on it, with an OK and a Cancel button. The OK button does this (psudocode):

    Sub cmdOK_Click()
    'extract the user record from the USER table with the ID of cboUsername
    'examine the txtPassword with the extracted USER's password
    'if passwords match then set a global variable called vUserLevel to the extracted USER's UserLevel field and then open the menu screen
    'if the passwords don't match, trash the txtPassword, set the focus there and show a message informing the user that the passwords don't match.

    End Sub

    My menu screen uses the vUserLevel and configures itself accordingly.

    Sorry, but I'd only use VBA for this, as opposed to using expressions with IIf.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  5. #5
    Join Date
    Jun 2008
    Posts
    163
    Haha! meanie! you're forcing me to really learn proper VBA! *goes off to try*

    hmm, wait.. "trash the txtPassword" <--- how do I set a field data to null? (I tried "null", but it wrote null on my record. T_T;;

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Well you know what they say... give a man a fish and he eats for today,... teach a man to fish....

    Me.txtPassword = "" or Me.txtPassword = Null will do the trick
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    ...teach a man to code and he'll be frustrated for life!
    George
    Home | Blog

  8. #8
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    looool!!
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  9. #9
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Sigged! ^^
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  10. #10
    Join Date
    May 2008
    Location
    London, UK
    Posts
    46
    Hello All, You seem to have been having fun in my absence!!
    Quote Originally Posted by StarTrekker
    ...I don't know how much of a "steer" you need,... I guess it might get you started? Where have you gotten stuck?
    To be honest I have fallen at the first hurdle, I have never attempted to make a login form before, so I've got as far as making the form with nothing behind it!

    My understanding of VB is limited - but I'm learning thanks to you lot!

    Quote Originally Posted by StarTrekker
    ...ability to pull the Windows Username from the system to determine security levels.
    Unfortunatly, the windows logins are used by multiple staff on many computers so I did not think this would be appropriate for this db. (Will be useful for other scenarios though).

    I'm really asking for help with the complete solution including a simple Login based on the above, which will not allow a "null" entry in the password field?

    Thanks!

  11. #11
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I'm really asking for help with the complete solution including a simple Login based on the above, which will not allow a "null" entry in the password field?
    Ok, so get started! Make a combo box for your usernames and a textbox for the password, an OK button and a Cancel button.

    Right click the Cancel button and choose Build Event (Code Builder) and type DoCmd.Quit. There, that's done.

    Now do the same with the OK button and enter this:

    Code:
        Dim rsUsers As Recordset
        
        If Me.txtPassword = "" Then
            MsgBox "Password cannot be empty."
        Else
            Set rsUsers = CurrentDb.OpenRecordset("SELECT * FROM tblAuthorisedUsers WHERE ID = " & Me.cboUsername)
            rsUsers.MoveFirst
            If Me.txtPassword = rsUsers!Password Then
                AccessLevel = rsUsers!AccessLevel
                DoCmd.Close , Me.Name
                DoCmd.OpenForm "SwitchboardFormName"
            Else
                AccessLevel = rsUsers!AccessLevel = 0
                MsgBox "Incorrect username or password"
                Me.txtPassword = ""
                Me.txtPassword.SetFocus
            End If
        End If
        Set rsUsers = Nothing
    Now there's no error handling in that and it's all untested code, so don't shoot me if there's a minor bug in it.

    Also, this would rely on a global variable called AccessLevel being declared.

    Good hunting

    Edit: Fixed minor obvious bugs.
    Last edited by StarTrekker; 07-07-08 at 11:10.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  12. #12
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Psst, ST, I've spotted a few mistakes in your code; want me to point them out?
    George
    Home | Blog

  13. #13
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Yeah I can see at least one now already... the > should be an = for a start

    Go for it, as I said it's untested... written on the fly, so I expect there to be little things to overcome. But then again, isn't adapting code to your needs all part of the learning process?!



    Edit: Corrected the blindingly obvious ones.... it was looking a bit "rs" for a while there
    Last edited by StarTrekker; 07-07-08 at 11:12.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  14. #14
    Join Date
    May 2008
    Location
    London, UK
    Posts
    46
    I am getting an error highlighting this section:
    Code:
    Set rsUsers = CurrentDb.OpenRecordset("SELECT * FROM tblAuthorisedUsers WHERE ID = " & Me.cboUsername)
    If the "WHERE ID = &..." is selecting the username (as I assume it is?) in my table usernames are in the "Username" coulmn, I have tried changing this but I'm still getting an error.

    I think I have everything else correct?

    Thanks very much for you help!

  15. #15
    Join Date
    May 2008
    Location
    London, UK
    Posts
    46
    Quote Originally Posted by StarTrekker
    Also, this would rely on a global variable called AccessLevel being declared.
    Ekkk! How do I do this and what should the variable do? I assume it will be a sort of;

    if "1" open "frmAdminSwitchboard" / if "2" open "frmUserSwitchboard"
    (only in non-comedy-code! )

Posting Permissions

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