CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 AD (ldap) authentication using WampServer 2.2 [SOLVED]

Print topic Send  topic

Author Message
rbroder

Posts: 67
Posted: 03/27/2018, 8:47 AM

Here's my setup and what I did on my testing server. WampServer 2.2 running php 5.3.10, Apache 2.2.21 on Windows 2012 R2. The key is getting the php_ldap library and driver to work. Make sure that the following files are COPIED from /wamp/bin/php/php5.3.10 to /wamp/bin/apache/apache2.2.21/bin: libsasl.dll, libeay32.dll,ssleay32.dll. The last 2 were already there in my case. The coding requires calling the ldap connection function and authenticating the user, then setting the Session Variables required by CCS5. If you don't set these variables the target page never loads and you are kicked back to the login page. I did not modify common.php. I just didn't call CCLoginUser().

Make a new login page using the CCS5 builder or modify your existing. Here is the CCS5 code with my modifications. Note that words between <> must be put in by you. Don't include the <>:

<?php  
//BindEvents Method @1-D3E6B248  
function BindEvents()  
{  
    global $Login;  
    global $CCSEvents;  
    $Login->Button_DoLogin->CCSEvents["OnClick"] = "Login_Button_DoLogin_OnClick";  
}  
//End BindEvents Method  
  
//Login_Button_DoLogin_OnClick @3-1454CF55  
function Login_Button_DoLogin_OnClick(& $sender)  
{  
    $Login_Button_DoLogin_OnClick = true;  
    $Component = & $sender;  
    $Container = & CCGetParentContainer($sender);  
    global $Login; //Compatibility  
//End Login_Button_DoLogin_OnClick  
  
//Login @4-A8229250  
    global $CCSLocales;  
    global $Redirect;  
    $username = $Container->login->Value;  
    $password = $Container->password->Value;  
    if ($Container->autoLogin->Value != $Container->autoLogin->CheckedValue) {  
        CCSetCookie("ccPOTESTLogin", "");  
    }  
	$ldap = ldap_connect("<your domain controller hostname or IP address");  
	ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);  
	ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);  
	//ldap_set_option($ldap, LDAP_OPT_DEBUG_LEVEL, 7);  
  
	$ldaprdn = '<your Domain name>'."\\".$username;  
	if(!$ldap){  
    //die( "LDAP Failed To Connect: ".ldap_error($ldap));  
	}  
	if (!$bind = ldap_bind($ldap, $ldaprdn, $password))  
	{  
		//die("user: ".$Container->password->Value);  
//    if ( !CCLoginUser( $Container->login->Value, $Container->password->Value)) {  
        $Container->Errors->addError($CCSLocales->GetText("CCS_LoginError"));  
        $Container->password->SetValue("");  
        $Login_Button_DoLogin_OnClick = 0;  
        CCSetCookie("ccPOTESTLogin", "");  
	} else {  
	//echo("ldap is good");  
		//add the next line to establish CCS session variables (id, group, username)  
		SetUserVariables($username);  
        global $Redirect;  
        if ($Container->autoLogin->Value == $Container->autoLogin->CheckedValue) {  
            $ALLogin    = $Container->login->Value;  
            $ALPassword = $Container->password->Value;  
            CCSetALCookie($ALLogin, $ALPassword);  
        }  
       // die("ready to redirect: ".ccGetParam("ret_link"));  
           //die(ccGetUserID()."; ".ccgetGroupID()."; ".ccgetUserLogin());  
  
        $Redirect = CCGetParam("ret_link", $Redirect);  
        $Login_Button_DoLogin_OnClick = 1;  
    }  
      
//End Login  
  
//Close Login_Button_DoLogin_OnClick @3-0EB5DCFE  
    return $Login_Button_DoLogin_OnClick;  
}  
//End Close Login_Button_DoLogin_OnClick  
  
//Page_BeforeInitialize @1-0242CABD  
function Page_BeforeInitialize(& $sender)  
{  
    $Page_BeforeInitialize = true;  
    $Component = & $sender;  
    $Container = & CCGetParentContainer($sender);  
    global $login; //Compatibility  
//End Page_BeforeInitialize  
  
//Custom Code @9-2A29BDB7  
// -------------------------  
    // Write your own code here.  
// -------------------------  
//End Custom Code  
  
//Close Page_BeforeInitialize @1-23E6A029  
    return $Page_BeforeInitialize;  
}  
//End Close Page_BeforeInitialize  
  
Function SetUserVariables($username)  
{  
$db = new clsDBSecurity();  
$sql = "Select userid, groupid from tblUsers WHERE username = ".$db->ToSQL($username, ccsText);  
//die($sql);  
$db->query($sql);  
$result = $db->next_record();  
//{die("userID= ". $db->f("userid"));  
ccSetSession("UserID", $db->f("userid"));  
ccSetSession("GroupID", $db->f("groupid"));  
CCSetSession("UserAddr", $_SERVER["REMOTE_ADDR"]);  
ccSetSession("UserLogin",$username);  
  
$db->close();  
}  
  
  
?>  
  

You can verify this is working by changing a user's password from your security database and then trying to log in. Try an incorrect password to test for that also.

Happy coding.
View profile  Send private message
kirchaj

Posts: 215
Posted: 05/10/2019, 12:57 PM

Has anyone else used LDAP as an authentication mechanism? I am being asked to convert an existing project with security levels to use our internal LDAP server.

Looking for any ideas, suggestions, pitfalls to consider.
Tony
View profile  Send private message
laneoc

Posts: 154
Posted: 06/12/2019, 7:56 AM

I use LDAP authentication without issues.
_________________
Lane
View profile  Send private message
laneoc

Posts: 154
Posted: 06/12/2019, 7:57 AM

I use LDAP authentication without issues.
_________________
Lane
View profile  Send private message
laneoc

Posts: 154
Posted: 06/12/2019, 7:58 AM

I use LDAP authentication without issues.
_________________
Lane
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.