rd_kellerman
asked on
Validate a Email address from active directory using javascript
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
Thanks Much,
Roger
ASKER
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
Thanks,
Roger
> 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?
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?
ASKER
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.Connec tion")
objConn.Open "Provider=ADsDSOObject;"
Set objAdoCmd = CreateObject("ADODB.Comman d")
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
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
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.Connec
objConn.Open "Provider=ADsDSOObject;"
Set objAdoCmd = CreateObject("ADODB.Comman
objAdoCmd.ActiveConnection
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
> 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?
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?
ASKER
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
Thanks,
Roger
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Thanks a lot,
Roger
ASKER
I'm going to close this and award points for the helpfull advice.
Thanks,
Roger
Thanks,
Roger
Thanks.
did you get it working with ldap: schema?
did you get it working with ldap: schema?
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.