C
Chris Davoli
Can somebody tell me how to authenticate USING SSL against an active
directory server? The below code works without SSL, but how do I get it to
work using SSL certificate and port 636? I'm assuming that the URL needs to
be changed to LDAPS://XX.XXX.X.XX:636/dc=XXXXXX,dc=XXXXX where LDAPS and Port
= 636 is specified. Is this true?
Public Function IsUserAuth( _
ByVal UserIDtoAuthenticate As String, _
ByVal PasswordToAuthenticate As String) As Boolean
Try
_ldapServerName = "XX.XXX.X.XX" ' LDAP server to
Authenticate against
_path = AppSettings("AD_Path") '"LDAP://" & _ldapServerName
& "/dc=XXXXXX,dc=XXXXX"
Dim oRoot As DirectoryEntry = New DirectoryEntry(_path,
UserIDtoAuthenticate, PasswordToAuthenticate)
oRoot.Username = AppSettings("AD_UserID")
oRoot.Password = AppSettings("AD_Password")
Dim obj As Object = oRoot.NativeObject
Dim oSearcher As DirectorySearcher = New
DirectorySearcher(oRoot)
oSearcher.Filter = "(SAMAccountName=" & UserIDtoAuthenticate
& ")"
Dim oResult As SearchResult
oSearcher.PropertiesToLoad.Add("cn")
oResult = oSearcher.FindOne
If oResult Is Nothing Then
'Authentication failed
Return False
End If
'Authentication success
Return True
Catch ex As Exception
If ex.GetBaseException.ToString.IndexOf("Logon failure:
unknown user name or bad password") > -1 Then
'Return "Logon failure: unknown user name or bad password"
'Authenticated failed
Return False
Else
If ex.GetBaseException.ToString.IndexOf("The directory
service is unavailable") > -1 Then
Return False
Else
Return False
'Throw New Exception("Error obtaining group names. "
& ex.Message)
End If
End If
End Try
End Function
directory server? The below code works without SSL, but how do I get it to
work using SSL certificate and port 636? I'm assuming that the URL needs to
be changed to LDAPS://XX.XXX.X.XX:636/dc=XXXXXX,dc=XXXXX where LDAPS and Port
= 636 is specified. Is this true?
Public Function IsUserAuth( _
ByVal UserIDtoAuthenticate As String, _
ByVal PasswordToAuthenticate As String) As Boolean
Try
_ldapServerName = "XX.XXX.X.XX" ' LDAP server to
Authenticate against
_path = AppSettings("AD_Path") '"LDAP://" & _ldapServerName
& "/dc=XXXXXX,dc=XXXXX"
Dim oRoot As DirectoryEntry = New DirectoryEntry(_path,
UserIDtoAuthenticate, PasswordToAuthenticate)
oRoot.Username = AppSettings("AD_UserID")
oRoot.Password = AppSettings("AD_Password")
Dim obj As Object = oRoot.NativeObject
Dim oSearcher As DirectorySearcher = New
DirectorySearcher(oRoot)
oSearcher.Filter = "(SAMAccountName=" & UserIDtoAuthenticate
& ")"
Dim oResult As SearchResult
oSearcher.PropertiesToLoad.Add("cn")
oResult = oSearcher.FindOne
If oResult Is Nothing Then
'Authentication failed
Return False
End If
'Authentication success
Return True
Catch ex As Exception
If ex.GetBaseException.ToString.IndexOf("Logon failure:
unknown user name or bad password") > -1 Then
'Return "Logon failure: unknown user name or bad password"
'Authenticated failed
Return False
Else
If ex.GetBaseException.ToString.IndexOf("The directory
service is unavailable") > -1 Then
Return False
Else
Return False
'Throw New Exception("Error obtaining group names. "
& ex.Message)
End If
End If
End Try
End Function