<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>LDAP Authentication Test</title> </head> <body> <% dim submit dim UserName dim Password dim domainname Domain = "" domainname="xxxxxx" ' Enter domain name Domain = "yyyyyy" ' Enter IP Address for Mail Server UserName = "" UserName1 = "" Password = "" Session("Usercode")="" submit = request.form("submit") if submit = "Authenticate" then UserName1=request.form("UserName") UserName = request.form("UserName")&"@"&domainname Password = request.form("Password") result = AuthenticateUser(UserName, Password, Domain) if result then Session("Usercode")=UserName1 response.write "<h3>Authentication Succeeded!</h3>" else response.write "<h3>Authentication Failed!</h3>" end if end if response.write "<hr><form method=post>" response.write "<table>" response.write "<tr>" response.write "<td><b>Username: </b></td><td><input type=""text"" name=""UserName"" value=""" & UserName1 & """ size=""30""></td>" response.write "</tr>" response.write "<tr>" response.write "<td><b>Password: </b></td><td><input type=""password"" name=""Password"" value=""" & Password & """ size=""30""></td>" response.write "</tr>" response.write "<tr>" response.write "<td> </td><td><input name=""submit"" type=""submit"" value=""Authenticate""></td>" response.write "</tr>" response.write "</table>" response.write "</form>" 'response.end function AuthenticateUser(UserName, Password, Domain) dim strUser ' assume failure AuthenticateUser = false strUser = UserName strPassword = Password strQuery = "SELECT cn FROM 'LDAP://" & Domain & "' WHERE objectClass='*' " set oConn = server.CreateObject("ADODB.Connection") oConn.Provider = "ADsDSOOBJECT" oConn.Properties("User ID") = strUser oConn.Properties("Password") = strPassword oConn.Properties("Encrypt Password") = true oConn.open "DS Query", strUser, strPassword set cmd = server.CreateObject("ADODB.Command") set cmd.ActiveConnection = oConn cmd.CommandText = strQuery on error resume next set oRS = cmd.Execute if oRS.bof or oRS.eof then AuthenticateUser = false else AuthenticateUser = true end if set oRS = nothing set oConn = nothing end function %> </body> </html>
Posted inGeneral