By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,659 Members | 1,678 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,659 IT Pros & Developers. It's quick & easy.

Connecting to LDAP authenticate and redirect

P: 1
Hi everyone

i have pull bits of code from everywhere and built this below.
all works perfect but i would like to have a login page where i put the username and pass and the redirect to another page passing a session number wher i will be able to filter by session.
can you please help.

thank you so much in advance.

Expand|Select|Wrap|Line Numbers
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
  2. -----------------------------filter user---------------------------
  3. <%
  4. fsCompletted = Request.QueryString("f")
  5.  
  6. If fsCompletted = 1 Then
  7.    ResultHTML = ProcessForm
  8. else
  9.    ResultHTML = "<br>"
  10. End If
  11.  
  12. Function ProcessForm
  13.    on error resume next
  14.    oUsername=Request.Form("username")
  15.    oPassword=Request.Form("password")
  16.    strUserName = Right(oUsername, Len(oUsername) - InStrRev(oUsername, "\"))
  17.    if InStr(strUserName, "@")>0 then
  18.       strUserName = Left(strUserName, InStr(strUserName, "@")-1)
  19.    end if
  20.    Set objDomain = GetObject("GC://rootDSE")
  21.    objADsPath = objDomain.Get("defaultNamingContext")
  22.    Set objDomain = Nothing
  23.    Set con = Server.CreateObject("ADODB.Connection")
  24.    con.provider ="ADsDSOObject"
  25.    con.Properties("User ID") = oUsername
  26.    con.Properties("Password") = oPassword
  27.    con.Properties("Encrypt Password") = False
  28.    con.open "Active Directory Provider"
  29.    Set Com = CreateObject("ADODB.Command")
  30.    Set Com.ActiveConnection = con
  31.    Com.CommandText ="select name,telephonenumber,mail FROM 'GC://"+objADsPath+"' where sAMAccountname='"+strUsername+"'"
  32.    Set rs = Com.Execute
  33.    VarInfo="<p>"+rs("name")+"<br>"+rs("telephonenumber")+"<br >"+rs("mail")+"</p>"
  34.    if err.number=0 then
  35.       HTML = "<p>"+rs("name")+"<br>"+rs("telephonenumber")+"<br >"+rs("mail")+"</p>"
  36.    else
  37.       HTML = "<p>Not Authenticated</p>"
  38.    end if
  39.    Session("mail") = Rs("mail")
  40.    rs.Close
  41.    con.Close
  42.    Set rs = Nothing
  43.    Set con = Nothing
  44.    ProcessForm=HTML
  45.    'ADUSER = rs("mail")
  46.    Session("userid") = VarInfo
  47. End Function
  48. PostURL = Request.ServerVariables("SCRIPT_NAME") & "?f=1" %> 
  49. <HTML>
  50.  <HEAD>
  51.  </HEAD>
  52. <BODY>
  53. <%=ResultHTML%>
  54. <%if request.querystring("f")="" then %>
  55.      <form method="post" Action="<%=PostURL%>">
  56.       <p>Username : <input type="text" Name="username" value="" Size="25">(yourDomain/username)</p>
  57.       <p>Password : <input type="password" Name="password" Size="25"></p>
  58.       <input Name=SubmitButton Value="Authenticate User" Type=submit>
  59.      </form>
  60. <%end if%>
  61.  
  62. --<%Response.Write Session("mail")%>
  63. </BODY>
  64. </HTML>
  65.  
Apr 17 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.