Drew Wutka
DWUTKA at Marlow.com
Mon May 28 12:45:14 CDT 2007
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 The information contained in this transmission is intended only for the person or entity to which it is addressed and may contain II-VI Proprietary and/or II-VI BusinessSensitve material. If you are not the intended recipient, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. You are notified that any review, retransmission, copying, disclosure, dissemination, or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited.