User and Password in MS ACCESS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • enambo
    New Member
    • Apr 2007
    • 2

    User and Password in MS ACCESS

    I am making a database program in MS Access I would to get help in giving a USER and PASSWORD in LOGIN Form. If the USER and PASSWORD is given in Table then we are entering the database else out of program or give an error.

    I do not want to give the USER and PASSWORD to be mentioned in vb codes.

    Please Help.


    Kartik
  • neelesh kumar
    New Member
    • Mar 2007
    • 44

    #2
    hi
    if there are 2 textboxes namely name and psword and table name is logintable containing username and password fields which are texts then
    then
    If name = DLookup("userna me", "logintable ", "[password]= '" & psword & "'") Then
    do some thing
    else Msgbox ""

    Comment

    • kartikss
      New Member
      • Apr 2007
      • 25

      #3
      Hi!!!

      Is there any option because when i create a form linking to the table of login and enter everyone user and password, i want the user to to enter the username and password , if the user name and password matches the login table, then it should continue or else it should show an error message.

      thanks & bye

      Kartik

      Comment

      • pks00
        Recognized Expert Contributor
        • Oct 2006
        • 280

        #4
        enambo
        Have u got a table created already?
        here is an example

        say u had a table called tblUsers, in it are two fields UserID and Pswd
        Now a simple form example, u would have a form with two prompts txtUser and txtPswd and a button called cmdLogin

        U would use the click event of cmdLogin to add your code

        eg

        Code:
        private sub cmdLogin_Click()
        
            Dim sPswd as string
        
        
            If IsNull(Me.txtUser) = True or IsNull(Me.txtPswd) = True then
                msgbox "Please enter both a userid and password"
                exit sub
            end if
        
            'DLOOKUP returns null if no record found therefore give it a default value of ""
            sPswd = NZ(DLOOKUP("Pswd","tblUsers","UserID='" & Me.txtUser & "'"),"")    
        
            If Me.txtPswd <> sPswd then
                msgbox "Invalid UserID/Password combination"
                exit sub
            end if
        
            'Continue with normal successful login code
        end sub


        kartikss, sorry I havent quite undertstood your post, care to elaborate?

        Comment

        • cknudstrup
          New Member
          • Apr 2007
          • 1

          #5
          I have a question to add to this. Is it possible to carry that user ID for that user as long as they are logged into the DB so that anytime the user opens a form or report (ie also query) that it filters the data for that user.

          I know this can be done using the Access built in security but I am trying to get away from that due to the environment.

          Thanks in advance

          Christian

          Comment

          • pks00
            Recognized Expert Contributor
            • Oct 2006
            • 280

            #6
            Originally posted by cknudstrup
            I have a question to add to this. Is it possible to carry that user ID for that user as long as they are logged into the DB so that anytime the user opens a form or report (ie also query) that it filters the data for that user.

            I know this can be done using the Access built in security but I am trying to get away from that due to the environment.

            Thanks in advance

            Christian
            define a global variable, then reference that

            Comment

            • Shokoth
              New Member
              • Apr 2007
              • 29

              #7
              Originally posted by pks00
              define a global variable, then reference that
              How would we go about doing that.
              What varialbe should we declare globally. is it the username (entered in a form), and the user name in the table?

              then refer to it, where all the forms use that username?

              Comment

              • rockdc1981
                New Member
                • Apr 2007
                • 51

                #8
                Dude you may want to try this got this from the net, and i was able to use it

                first create a table and name it tblEmployees, create the ff fields, lngEmpID(pk, AutoNumber),str EmpName(txt),st rEmpPassword(tx t),fullname(txt ),strAccess (text).

                then create ur log on form frmLogon

                using designview, insert a combobox, name it cboEmployee, and row source is SELECT tblEmployees.ln gEmpID, tblEmployees.st rEmpName FROM tblEmployees; on the after update event paste te ff code to set focus to textbox u wil create next,
                Private Sub cboEmployee_Aft erUpdate()
                'After selecting user name set focus to password field
                txtPassword.Set Focus
                End Sub

                Now create ur password text box,

                name it txtPassword.

                Now insert a button and name it cmdLogin

                Paste the code below on the on click event

                Private Sub cmdLogin_Click( )

                'Check to see if data is entered into the UserName combo box

                If IsNull(Me.cboEm ployee) Or Me.cboEmployee = "" Then
                MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
                Me.cboEmployee. SetFocus
                Exit Sub
                End If

                'Check to see if data is entered into the password box

                If IsNull(Me.txtPa ssword) Or Me.txtPassword = "" Then
                MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
                Me.txtPassword. SetFocus
                Exit Sub
                End If

                'Check value of password in tblEmployees to see if this matches value chosen in combo box

                If Me.txtPassword. Value = DLookup("strEmp Password", "tblEmploye es", "[lngEmpID]=" & Me.cboEmployee. Value) Then

                lngMyEmpID = Me.cboEmployee. Value

                'Close logon form and open splash screen

                DoCmd.close acForm, "frmLogon", acSaveNo
                DoCmd.OpenForm "Switchboar d"
                'Create your switchboard or change this to any other form u want the user to see upon log in

                Else
                MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
                Me.txtPassword. SetFocus
                End If

                'If User Enters incorrect password 3 times database will shutdown

                intLogonAttempt s = intLogonAttempt s + 1
                If intLogonAttempt s > 3 Then
                MsgBox "You do not have access to this database. Please contact your system administrator." , vbCritical, "Restricted Access!"
                Application.Qui t
                End If

                End Sub


                You now have your Log in form

                Hope i was able to help...good luck!

                Comment

                • pks00
                  Recognized Expert Contributor
                  • Oct 2006
                  • 280

                  #9
                  rockdc1981

                  have a look at the code I posted. does that make sense to you?
                  its the same approach as the code you posted
                  Im hoping it makes sense to you so hopefully the OP understands it also

                  Comment

                  • kartikss
                    New Member
                    • Apr 2007
                    • 25

                    #10
                    Code:
                    Private Sub Command12_Click()
                    
                    
                    If USER_ID = [Form_LOGIN MASTER].ID And PASSWORD = [Form_LOGIN MASTER].PWD Then
                    
                    MsgBox (Form_Login.USER_ID + " - " + "WELCOME TO ENAM SECURITIES PVT LTD")
                    
                    
                    
                     Dim stDocName As String
                     Dim stLinkCriteria As String
                     
                      Me.Visible = False
                      DoCmd.OpenForm "STARTUP", acNormal, , , acFormEdit, acWindowNormal
                       
                        
                      stDocName = "STARTUP"
                      DoCmd.OpenForm stDocName, , , stLinkCriteria
                        
                    
                    Else
                    
                    MsgBox ("Incorrect User ID or Password - Please try again.")
                    
                    End If
                    
                    
                    End Sub
                    PLS CHECK THE ABOVE CODE AND LET ME KNOW THE ERROR.
                    AS THIS WORK FINE. IT ACCEPTS ONLY FIRST RECORD AND NOT REST.
                    REST OF RECORD : I GET THE MESSAGE IE MsgBox ("Incorrect User ID or Password - Please try again.")

                    IS THERE ANY OTHER OPTION DO LET ME KNOW.

                    THANKS & BYE

                    KARTIK
                    Last edited by MMcCarthy; May 6 '07, 01:56 AM. Reason: code tags - use square brackets

                    Comment

                    • meLady
                      New Member
                      • Apr 2007
                      • 27

                      #11
                      Hello everyone,

                      Can anyone reply to kartikss's queries ... I am also interested in knowing the problems ... so, please reply to his question (^_^)

                      Comment

                      • MMcCarthy
                        Recognized Expert MVP
                        • Aug 2006
                        • 14387

                        #12
                        Originally posted by kartikss
                        Code:
                        Private Sub Command12_Click()
                        
                        
                        If USER_ID = [Form_LOGIN MASTER].ID And PASSWORD = [Form_LOGIN MASTER].PWD Then
                        
                        MsgBox (Form_Login.USER_ID + " - " + "WELCOME TO ENAM SECURITIES PVT LTD")
                        
                        
                        
                         Dim stDocName As String
                         Dim stLinkCriteria As String
                         
                          Me.Visible = False
                          DoCmd.OpenForm "STARTUP", acNormal, , , acFormEdit, acWindowNormal
                           
                            
                          stDocName = "STARTUP"
                          DoCmd.OpenForm stDocName, , , stLinkCriteria
                            
                        
                        Else
                        
                        MsgBox ("Incorrect User ID or Password - Please try again.")
                        
                        End If
                        
                        
                        End Sub
                        PLS CHECK THE ABOVE CODE AND LET ME KNOW THE ERROR.
                        AS THIS WORK FINE. IT ACCEPTS ONLY FIRST RECORD AND NOT REST.
                        REST OF RECORD : I GET THE MESSAGE IE MsgBox ("Incorrect User ID or Password - Please try again.")

                        IS THERE ANY OTHER OPTION DO LET ME KNOW.

                        THANKS & BYE

                        KARTIK
                        How are you getting USER_ID and Password?

                        Comment

                        • kartikss
                          New Member
                          • Apr 2007
                          • 25

                          #13
                          Originally posted by mmccarthy
                          How are you getting USER_ID and Password?
                          Presently i am working with help of coding

                          for ex
                          Code:
                          private sub command1_click()
                          
                          if id= form_login.id=kartik and pwd=form_login.password=123 or form_login.id=guest and form_login.password=g12 then
                          
                          open the particular form
                          
                          else
                          
                          error message
                          
                          endif
                          
                          end sub
                          but now i want work with help of table name security control and table containing following details ie

                          userid (text), password (text), enable (y/n), visible (y/n)

                          if userid - enable = n then it should disable that option else it should enable
                          if userid - visible = n then it should disappear that option else it should appear

                          how do i work on this option

                          pls help me - urgently

                          if you require i will send the print screen of file.


                          Kartik

                          Comment

                          • NeoPa
                            Recognized Expert Moderator MVP
                            • Oct 2006
                            • 32645

                            #14
                            Originally posted by mmccarthy
                            How are you getting USER_ID and Password?
                            Originally posted by kartikss
                            Presently i am working with help of coding

                            for ex
                            Code:
                            private sub command1_click()
                            
                            if id= form_login.id=kartik and pwd=form_login.password=123 or form_login.id=guest and form_login.password=g12 then
                            
                            open the particular form
                            
                            else
                            
                            error message
                            
                            endif
                            
                            end sub
                            but now i want work with help of table name security control and table containing following details ie

                            userid (text), password (text), enable (y/n), visible (y/n)

                            if userid - enable = n then it should disable that option else it should enable
                            if userid - visible = n then it should disappear that option else it should appear

                            how do i work on this option

                            pls help me - urgently

                            if you require i will send the print screen of file.


                            Kartik
                            Kartik,
                            If you do not reply correctly then you cannot expect any response.
                            You have not answered Mary's question.
                            You have simply asked the same question again and have posted some strange code with it that has never seen an Access database code window.

                            Comment

                            • Denburt
                              Recognized Expert Top Contributor
                              • Mar 2007
                              • 1356

                              #15
                              I can only refer anyone back to post #4 I will repost the code that pks00 posted and try to add a few notes to help you understand. You need to take the values entered into the form then compare them to the information in the table. pks is using a function called DLookup, using this function he gathers the password information that is needed from the table for that particular user.

                              In this example you are telling DLookup to get the field information from "Pswd" in the table called "tblUsers" The final portion tells DLookup what the criteria is for pulling the one record you want so you can verify that the "Pswd" field matches the one on the form. Hence:"UserID=' " & Me!txtUser & "'

                              The resulting password for me!txtUser will be stored in the variable sPswd for comparison purposes.

                              When in the VB window you can use the "debug.prin t sPswd" statement to verify you are picking up this information, the results will show in the immediate window if there are any to return.

                              Also in the VB window try highlighting the word DLookup and press F1.

                              Code:
                              private sub cmdLogin_Click()
                              
                                  Dim sPswd as string
                              
                                  If IsNull(Me!txtUser) = True or IsNull(Me!txtPswd) = True then
                                      msgbox "Please enter both a userid and password"
                                      exit sub
                                  end if
                                   
                                  'DLOOKUP returns null if no record found therefore give it a default value of ""
                                  sPswd = NZ(DLOOKUP("Pswd","tblUsers","UserID='" & Me!txtUser & "'"),"")    
                              debug.print sPswd
                                  If Me!txtPswd <> sPswd then
                                      msgbox "Invalid UserID/Password combination"
                                      exit sub
                                  end if
                              
                                  'Continue with normal successful login code
                              end sub
                              Hope this helps.

                              Comment

                              Working...