asp - LDAP 사용하여 인증하기 방법
제목 : asp - LDAP 사용하여 인증하기 방법
If Trim(request.querystring("error")) <> "" Then
response.write "<p class=""detailtextbold""><font size=""2"" color=""maroon"">" & Trim(request.querystring("error")) & "</font></p>"
End If
if submit = "Log In" then
UserName = request.form("UserName")
Password = request.form("Password")
Domain = "mydomain.com"
result = AuthenticateUser(UserName, Password, Domain)
if result then
session("sess_var") = request.form("UserName")
response.redirect("homepage.asp")
else
response.redirect("loginpage.asp?error=The%20account%20or%20password%20is%20invalid!%20%20Please%20try%20again.")
end if
end if
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
내용 :
예제 소스 파일 :