Results 1 to 7 of 7
  1. #1
    ThornofSouls's Avatar
    ThornofSouls is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Sweden, Gothenburg
    Posts
    42

    LoginForm Validation of User

    Hi i have been working on a login form with a username and password input from the user. The code seams run just fine to the point when i want to make sure both the username and password are validated. My idea was to compare two boolean values with each other, and if they were true, then proceed.
    //Thorn



    The code on the Login form. (frmLogin)
    Code:
    Option Compare Database
    Option Explicit
    
    
            
    Private Sub cmd_Login_Click()
        
        On Error GoTo Err_Process
                Dim rs As Recordset
                Dim Crit1 As Boolean
                Dim Crit2 As Boolean
                Dim i As Integer
                Dim x As Integer
                        i = 1
                        x = (10 ^ (2))
        Set rs = CurrentDb.OpenRecordset("tblEmployees", dbOpenSnapshot, dbReadOnly)
        
        rs.FindFirst "UserName = "" & Me.txtUserName & """
            
            Me.txtUserName.SetFocus
            If rs.NoMatch = True Then
                    Me.lbl_Login_Err.Visible = True
                    Me.txtUserName.SetFocus
                    Crit1 = False
            Else
                    Me.lbl_Login_Err.Visible = False
                    Crit1 = True
            End If
                        
            If rs!PW <> Nz(Me.txt_PW, "") = True Then
                    Me.lbl_Login_Err.Visible = True
                    Me.txt_PW.SetFocus
                    Crit2 = False
            Else
                    Me.lbl_Login_Err.Visible = False
                    Crit2 = True
    '                DoCmd.Close acForm, Me.Name
    '                DoCmd.OpenForm "frmMenu"
            End If
                        If Crit1 And Crit2 = True Then
                            DoCmd.Close acForm, Me.Name
                            DoCmd.OpenForm "frmMenu"
                        End If
    
    
    '    Do While i < x
    '        i = i + 1
    '        Me.lbl_Login_Err.Visible = True
    '        Debug.Print i
    '                If i = x Then
    '                    Me.lbl_Login_Err.Visible = False
    '                    Debug.Print i
    '                    i = i - i
    '                    Exit Do
    '                End If
    '    Loop
    
    
    
    
    '        Do
    '            i = i + 1
    '            Debug.Print i
    '                If i = x Then
    '                        Me.lbl_Login_Err.Visible = False
    '                        Debug.Print i
    '                        i = i - i
    '                        Exit Do
    '                End If
    '        Loop
    Exit_Process:
            Exit Sub
    Err_Process:
            Resume Exit_Process
    End Sub
    
    
    Private Sub cmdEN_Click()
                Me.lblUserName.Caption = "Username:"
                Me.lbl_PW.Caption = "Password:"
                Me.lbl_Login_Err.Caption = "Wrong password or Username"
    End Sub
    
    
    Private Sub cmdSE_Click()
    '        MsgBox lblUserName.Height
    '        MsgBox lblUserName.Width
            Me.lblUserName.Caption = "Användarnamn:"
            Me.lbl_PW.Caption = "Lösenord:"
            Me.lbl_Login_Err.Caption = "Fel Användarnamn eller Lösenord"
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Check login against the windows authentication...

    Code:
    SUB btnLogin_Click()
    Dim sUser As String, sPass As String, sDom As String
    
    sUser = txtUser
    sPass = txtPass
    sDom = txtDom
    
    If WindowsLogin(sUser, sPass, sDom) Then
       mbSafe = True
       DoCmd.OpenForm "frmMainMenu"
       DoCmd.OpenForm "frmLogin"
       DoCmd.Close
    Else
       MsgBox "LOGIN INCORRECT", vbCritical, "Bad userid or password"
    End If
    
    '-----------------
    Public Function WindowsLogin(ByVal strUserName As String, ByVal strpassword As String, ByVal strDomain As String) As Boolean
    '-----------------
            'Authenticates user and password entered with Active Directory.
    
            On Error GoTo IncorrectPassword
            
            Dim oADsObject, oADsNamespace As Object
            Dim strADsPath As String
            
            strADsPath = "WinNT://" & strDomain
            Set oADsObject = GetObject(strADsPath)
            Set oADsNamespace = GetObject("WinNT:")
            Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, strDomain & "\" & strUserName, strpassword, 0)
            
            WindowsLogin = True    'ACCESS GRANTED
            
    ExitSub:
            Exit Function
            
    IncorrectPassword:
            WindowsLogin = False   'ACCESS DENIED
            Resume ExitSub
    End Function

  3. #3
    ThornofSouls's Avatar
    ThornofSouls is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Sweden, Gothenburg
    Posts
    42
    As I understand it, This code them last login details, to the Windows account that last logged in to the machine. Linked to a specific domain.
    or am i wrong?

    it feels like this subroutine is above my current knowledge of vba. if you do not mind it, I would appreciate a summarized förklaning how the code handles inlognings data.
    //Thorn

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Yes , it uses window authentication, for user/password/domain check.
    if it returns false, login failed.

  5. #5
    ThornofSouls's Avatar
    ThornofSouls is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Sweden, Gothenburg
    Posts
    42
    Do you happen to have a sample db so i can take a look on the table structure?

  6. #6
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    there are no tables. it is code to validate the login.

  7. #7
    ThornofSouls's Avatar
    ThornofSouls is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Sweden, Gothenburg
    Posts
    42
    Oh
    I see..

    Thx

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

Similar Threads

  1. Replies: 2
    Last Post: 06-16-2015, 03:52 AM
  2. Replies: 9
    Last Post: 04-08-2014, 10:39 AM
  3. Replies: 13
    Last Post: 11-18-2013, 02:20 PM
  4. Replies: 1
    Last Post: 07-20-2012, 05:35 PM
  5. Replies: 8
    Last Post: 06-30-2010, 10:57 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