Gustav Brock
Gustav at cactus.dk
Mon May 28 13:08:03 CDT 2007
Hi Drew
Thanks!
What is/was the purpose of strLDAPConn?
/gustav
>>> DWUTKA at Marlow.com 28-05-2007 19:45 >>>
Hey folks, I've spent most of the weekend updating a system I built
about 7 years ago. It's our Help Desk program. One of the features
I've always wanted to add was an electronic signature capability. To do
this, I wanted to be able to prompt for a user's NT Name and Password,
and validate it. It is very simple to get the currently logged on
user's NT name, but for an electronic signature, it is much better to
prompt for credentials. I found code, years ago, that did this, but it
wasn't perfect, because it didn't work for my NT account. I have an odd
character in my password, and everything I had found would fail to
authenticate with passwords that had odd ascii values in them. (Even
though I can log onto our network fine).
This weekend I found (and tweaked) a process that works perfectly. I
figured I would share the validation function with ya'all: (It needs a
reference to ADO)
Function ValidateNTUser(strUserName As String, strPassword As String) As
Boolean
On Error Resume Next
Dim strDomain As String
Dim conLDAP As ADODB.Connection
Dim strSQL As String
Dim strLDAPConn As String
Dim rsUser As ADODB.Recordset
strDomain = GetObject("LDAP://RootDSE").Get("defaultNamingContext")
Set conLDAP = New ADODB.Connection
conLDAP.Provider = "ADSDSOOBject"
strSQL = "Select AdsPath, cn From 'LDAP://" & strDomain & "' where
objectClass='user' and objectcategory='person' and SamAccountName='" &
strUserName & "'"
conLDAP.Provider = "ADsDSOObject"
conLDAP.Properties("User ID") = strUserName
conLDAP.Properties("Password") = strPassword
conLDAP.Properties("Encrypt Password") = True
conLDAP.Open "DS Query", strUserName, strPassword
Err.Clear
Set rsUser = conLDAP.Execute(strSQL)
ValidateNTUser = False
If Err.Number = 0 Then
If Not (rsUser Is Nothing) Then
If Not (rsUser.EOF And rsUser.BOF) Then
ValidateNTUser = True
End If
End If
End If
End Function
Drew