Solved

Validate a Email address from active directory using javascript

Posted on 2006-11-16
10
1,146 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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
 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

776 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