LDAP Based Authentication Through Jscript

I am attempting to authenticate users through JScript (server side) code and Active Directory. In its current behavior the code below throws an empty exception (e.description == "") if the username and password are invalid and if they are valid the exception "Class doesn't support Automation" is thrown. Thank you very much for your advice!
function AuthenticateUser(sUsername, sPassword)
{
   try {
      var ADS_SECURE_AUTHENTICATION = 1;
      var ADS_USE_ENCRYPTION = 2;
      var objLDAP = GetObject("LDAP:");
      if(objLDAP) {
         var sResult = objLDAP.OpenDSObject("LDAP://xxxxxxx.xxxx.xxx/cn=users,dc=xxxxxx,dc=xxxx,dc=xxx", sUsername + "@XXXXXXX", sPassword, ADS_SECURE_AUTHENTICATION || ADS_USE_ENCRYPTION);
      }
   }
   catch (e) {
      log("Exception in AuthenticateUser: " + e.description);
      throw(e);
   }
}

Open in new window

LVL 19
LordOfPortsAsked:
Who is Participating?
 
hieloConnect With a Mentor Commented:
Source: http://community.installshield.com/showthread.php?t=115480
"Hi All, The following jscript(WSH) for Ldap access, works fine on my Win2k system..."
---------------------------------------------------------------------------
Ldap Jscript:
---------------------------------------------------------------------------
// cscript chkLdapAcc.js
//
// The following is the OpForce install parameters for LDAP.
// Provider: -> LDAP://192.168.6.20/dc=qa,dc=com
// User DN : => cn=Admin,cn=Users,dc=qa,dc=com
// Password: -> Admin
//
ADS_SECURE_AUTHENTICATION = 0x1
var user;
var provLdap;
var gblError= false;
var Container = "DC=qajareva,DC=COM";
// Create LDAP obj
try{
provLdap = GetObject("LDAP:") ;
WScript.Echo("Success: LDAP Object created");
}
catch(err)
{
WScript.Echo('LDAP Connection Error: '+err.description);
gblError = true;
}
if(!gblError)
{
// Login
try{
user = provLdap.OpenDSObject("LDAP://company.com/"
+ Container
, "Admin@qa.com"
,"Admin", ADS_SECURE_AUTHENTICATION);
}
catch(err)
{
WScript.Echo('LDAP Login Error: '+err.description);
gblError = true;
}
}
if(!gblError)
{
//Work with the object
WScript.Echo('UserName : ' +user.Name)
WScript.Echo('UserClass: ' +user.Class)
WScript.Echo('USerGUID : ' +user.GUID)
WScript.Echo("")
}

Open in new window

0
 
LordOfPortsAuthor Commented:
Most excellent. Thank you very much!
0
All Courses

From novice to tech pro — start learning today.