Check Network Credentials to access application in

Well I wish I could tell you I was a little less sore today. I am not. In fact, it is worse. When I got out of bed today the backs of my legs felt like they were on fire. Oh well. Hope you are doing better than I am at this point.

Anyway, at times we want to use the user’s network credentials in order to allow them to access an application. Here is what I came up with:

Join me on Facebook

// Inputs:UserName,
    // Returns:true (validated) or
    // Assumes:.NET
    Public Class cLDAP
    Private m_Initial As String
    Private m_ldapServer As String
    Private m_ldapPort As String ‘389
    Private m_OrgUnit As String ‘ou=
    Private m_Org As String ‘o=
    Private m_Password As String
    Public Sub New(ByVal m_Initial As String, _
    ByVal m_Password As String, _
    Optional ByVal m_OrgUnit As String = "[ou=YourOrgUnit]", _
    Optional ByVal m_Org As String = "[o=YourOrg], _
    Optional ByVal m_ldapServer As String = "YourLDAPServer", _
    Optional ByVal m_ldapPort As String = "389")
    Me.m_Initial = m_Initial
    Me.m_Password = m_Password
    Me.m_OrgUnit = m_OrgUnit
    Me.m_Org = m_Org
    Me.m_ldapServer = m_ldapServer
    Me.m_ldapPort = m_ldapPort
    End Sub
Public Function Authenticate() As Boolean
    If m_Initial = "" Or m_Password = "" Then Return False
    Dim con As Object = GetObject("LDAP:")
    Dim conStr As String = "uid=" & m_Initial & "," & m_OrgUnit & "," & m_Org
    Dim ldConn As Object = _
    con.openDSObject("LDAP://" & m_ldapServer & ":" & m_ldapPort, _
    conStr, m_Password, 0)
    Return True
    Catch ex As Exception
    Return False
    End Try
    End Function
    End Class
    Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
    Dim ccLDAP As New cLDAP("YourLoginName", _
    "YourLoginPassword", _
    "ou=[yourOrganizationUnit]", _
    "o=[yourOrganization]", _
    "YourLdapServer, _
    m_Authenticated = ccLDAP.Authenticate
    retries += 1
    If retries = 4 Or m_Authenticated Then
    ErrorProvider1.SetError(txtPassword, "")
    ErrorProvider1.SetError(txtPassword, _
    "Invalid Password (retries left = " & 4 – retries & ")")
    txtPassword.Text = ""
    End If
    End Sub

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: