Here are the facts
I need to create a form that authenticates existing users in an exchange server using ldap queries. The form will be in a different server.
So what any particular user will be doing, is visiting this form. type username and password. the form should authenticate using the data on the exchange server, and if the user exist then granted access to a redirect that i will place on the form.
here is the code i am using. Any help is valuable.
<% @LANGUAGE="VBSCRIPT" EnableSessionState = False %>
<%
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>
I need to create a form that authenticates existing users in an exchange server using ldap queries. The form will be in a different server.
So what any particular user will be doing, is visiting this form. type username and password. the form should authenticate using the data on the exchange server, and if the user exist then granted access to a redirect that i will place on the form.
here is the code i am using. Any help is valuable.
<% @LANGUAGE="VBSCRIPT" EnableSessionState = False %>
<%
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>