Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login page that authenticates agains LDAP (8 forums and no luck)

Status
Not open for further replies.

alexsab

Programmer
Oct 2, 2009
4
US
Hi, I hope someone can help me.

I have a form build in classic ASP, that is trying to authenticated against LDAP in a different server than where the form is located.

If the users exist they will be redirected to a new page. if not they will be prompt to try again for username and password.

I have read that I need to have anonymous log in disabled for this to work, which I have done.

As of right now, I always get authentication failed. the form i am working with is this, if this is incorrect please do correct me. i have found 3 different forms which i have try and i dont know what else to do.

<%
Option Explicit
Response.Buffer = True

'// 1. Form Validation
Dim Submit, UserName, Password, Domain, Result, Message
Submit = Request.Form("Submit")

If Submit = "Authenticate" Then

'Get the input from your HTML form
UserName = Request.Form("UserName")
Password = Request.Form("Password")
Domain = Request.Form("Domain")

'Call the AuthenticateUser() function to do the verification process
Result = AuthenticateUser(UserName, Password, Domain)

If Result Then
'If user exist, then redirect to success page
Response.Redirect ("success.asp")
Else
'If user don't exist, redirect to error page
Response.Redirect ("error.asp")
End If
End If

'// 2. Authenticate Function
Function AuthenticateUser(UserName, Password, Domain)
Dim strUser, strPassword, strQuery, oConn, cmd, oRS

'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
%>

<html>
<head>
<title>Using Microsoft Active Directory Authentication</title>
</head>
<body>

<form name="DomainAuthentication" method="post">
Username:<input type="text" name="UserName" size="45">
Password:<input type="password" name="Password" size="45">
AD Domain:<input type="text" name="Domain" size="45">
<input name="submit" type="submit" value="Authenticate">
</form>

</body>
</html>
 
try this... i just cant get it pulling the groups their part of now :/ i found this code and it works but not completely to what i need.

Code:
<!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



UserName = ""  
Password = ""
Domain = "DOMAIN"

submit = request.form("submit")

if submit = "Authenticate" then
UserName = request.form("UserName")
Password = request.form("Password")
Domain = request.form("Domain")
result = AuthenticateUser(UserName, Password, Domain)
if result then
response.write "<h3>Authentication Succeeded!</h3>"
	if isGroup then
		response.write "User is in InfoDirectory group!"
	end if
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:&nbsp;</b></td><td><input type=""text""name=""UserName"" value=""" & UserName & """ size=""30""><br><small>Enter as""DOMAIN\UserName"" or ""UserName@sub.domain.com"" or ""\UserName"" in asingle domain environment</small></td>"
response.write "</tr>"
response.write "<tr>"
response.write "<td><b>Password:&nbsp;</b></td><td><input type=""password"" name=""Password"" value=""" & Password & """size=""30""></td>"
response.write "</tr>"
response.write "<tr>"
response.write "<td><b>AD Domain:&nbsp;</b></td><td><input type=""text""name=""Domain"" value=""" & Domain & """ size=""30""><br><small>Enter the ADServer FQDN, IP Address, or DN<br>Examples: ""adserver1.ourdomain.com"" or ""192.168.1.150"" or ""192.168.1.150/dc=adserver1,dc=ourdomain,dc=com""</small></td>"
response.write "</tr>"
response.write "<tr>"
response.write "<td>&nbsp;</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
oConn.close
set oRS = nothing
set oConn = nothing

end function

%>

</body>
</html>

Running in circles is what I do best!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top