Solved

Validate a Email address from active directory using javascript

Posted on 2006-11-16
10
1,132 Views
Last Modified: 2008-02-01
I have a form text field that contains a users Email address. I use an active directory LDAP query (with asp) to get the initial input for the Email text box. When the user submits the form a javascript include file is used to validate all the fields. What I need to do is to check the address against AD again so if the address is changed by the user the final form validation will catch it before submit. The problem is that the code for the LDAP query is using asp and I need to call to somehow check the address when the javascript validation hits the Email box just before the final submit. This is on a Corporate intranet running in a windows environment. Is there any way for javascript to query AD using LDAP, that would make it easy, but so far I can't find anything for this.

Thanks Much,
Roger
0
Comment
Question by:rd_kellerman
  • 5
  • 5
10 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17960830
> .. check the address against AD again so if the address is changed by the user the final form validation will catch it before submit.
how would you check against the server's AD if the reuest has not been submitted to the server?
Probably I missed something here, then please explain.

>  I need to call to somehow check the address when the javascript validation hits the Email box just before the final submit.
This is a useless attempt, 'cause you need to check the validity on ther server again, 'cause anything can be manipulated on client side.

I.g. checking for a valid email adress syntax is a complex regualr expression, a very simple and incomplete example can be found at
http://examples.oreilly.com/regex/.

I'd simply use LDAP to do the work for you. Check the given email adress for special LDAP characters --like *,|(): -- and escape them, then make an LDAP search and check the reults.
0
 

Author Comment

by:rd_kellerman
ID: 17961093
I hope I can clarify this. In the global.asa I use vbscript to get the logged in users Email address from AD when the page opens. I use this to populate the input box automatically. Then before I submit that from the form I want to check the Email again in case it's changed. I have a javascript that checks for blank input, dates, required fields...etc. In this script it can look at the Email field before sumbitting. From this javascript I want to check the address against AD using the vbscript that I use to get it initally. I think I am just wondering if I can somehow call or use the vbscript when the js finds that email field?  I cannot use a regular exp because I have to check if the user's Email is in our AD database, this is a requirement to submit the form.

Thanks,
Roger
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17967589
> I have a javascript that checks ..
do you mean javascript on the client? That's useless, as already explained.

> From this javascript I want to check the address against AD using the vbscript ..
again: are you talking about the script on the server or on the client?
0
 

Author Comment

by:rd_kellerman
ID: 17968016
Not sure what you mean by useless - I thought form validation was traditionally done on the client before submitting a form??  Both of these are referring to client side scripts that check for valid input before the form submits. I have it working now by calling the vbScript function to search for valid AD address from a Javascript validation script - both client side. I am wondering if this can be done without scitching from Javascript to vbScript?

 Here's the client vbScript code for AD search:

//vbscript function to check address against AD.  Can this code be converted to Javascript?
function ADSearch(p_searchStr, p_type)
' Search for a User Account in Active Directory
      Dim objConn
      Dim objRecordSet
      Dim objAdoCmd
      Dim strDomain
      Dim strSvrID
      Dim strSvrPw
      Dim strQuery
      Dim strAD_Context
      
      ''credentials for AD
      strAD_Context = "DC=domain,DC=something,DC=blah"
      If p_type <> "" Then
            Select Case p_type
                Case "mail"
                      strQuery = "mail=" & p_searchStr
                Case "UserId"
                      strQuery = "samAccountName=" & p_searchStr
                Case Else
                      strQuery = "unknown"
            End Select
      End If            
      If strQuery <> "" And strQuery <> "unknown" Then
            dtStart = TimeValue(Now())
            Set objConn = CreateObject("ADODB.Connection")
            objConn.Open "Provider=ADsDSOObject;"
            Set objAdoCmd = CreateObject("ADODB.Command")
            objAdoCmd.ActiveConnection = objConn
            objAdoCmd.CommandText = _
                "<LDAP://" & strAD_Context & ">;(&(objectCategory=User)" & _
                     "(" & strQuery & "));samAccountName, mail;subtree"
            Set objRecordSet = objAdoCmd.Execute
            If objRecordset.RecordCount = 0 Then
                ADSearch = false
            Else
                ADSearch = true
            End If
            objConn.Close
      End If
End function

Thanks,
Roger
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17970802
>  I thought form validation was traditionally done on the client before submitting a form?
yeah, 'til people realised that it's possible to fool the server if they can circumvent the client side validation ;-)
Unless you don't care about whatever the client sends your server and doesn't harm it, you have to do *all* validation on the server.

> I have it working now by calling the vbScript function to search for valid AD  ..
if you still have it working with vb, why do you then need javascript also?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:rd_kellerman
ID: 18019509
I'm working in an corporate Intranet so it's not a security issue with the validation, at least as far as I can see. I am just using the "valdation" to get an Email address from the AD so the Email is sent to a user in our network.  As to the getting the credentials with Vbscript question. I thought it would be a little "better" to do this in the same language as the validation routine. I guess I'm just curious if it would be possibe with Javascript?  Sorry for the delayed response, I was out for the Thanksgiving holiday.

Thanks,
Roger
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 18034916
ok, as you don't care about security ...

Don't know how your AD is setup, which protocol to use etc.
But I guess it uses LDAP, then you may use XMLHttpRequest() with the ldap: schema to query your AD.
It's something like:
    var req = new XMLHttpRequest();
    req.open('GET', 'ldap://fqdn-of-your-AD/o=your-organisation,ou=your-group, ..... ?emailAddress

(where emailAddress is the LDAP entry's attribute for the email)
0
 

Author Comment

by:rd_kellerman
ID: 18036994
Yes it's LDAP. I'll test this to see if I can get it to work.  I know it's not that big of a deal to use vbscript with javascript, I just was wondering how it could be done. I have not found an example of this anywhere.

Thanks a lot,
Roger
0
 

Author Comment

by:rd_kellerman
ID: 18117327
I'm going to close this and award points for the helpfull advice.

Thanks,
Roger
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 18117518
Thanks.
did you get it working with ldap: schema?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now