Thursday, 13 September 2018

Authenticate user through LDAP, Active Directory

Please go through the code below - Codeigniter
--------------------------------------------------------------------------------------

Config - define
---------------------------------------------------
define('ldap_serverhost', '192.168.24.31');
define('ldap_basedn', 'domainname');


Controller code - Login
----------------------------------------------------
$username = $this->input->post('userid', TRUE);
$password = $this->input->post('password', TRUE);
$entries = ldap_connention($username, $password);


Helper code - custom_helper
----------------------------------------------------

if (!function_exists('ldap_connention')) {
    /**
     * Create LDAP CONNECTION
     *
     */
    function ldap_connention($handle, $password)
    {

        $server = ldap_serverhost;
        $basedn = ldap_basedn;
        $dn = ldap_basedn . "\\" . $handle;

        $connect = ldap_connect($server);
        ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
        ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);

//var_dump(ldap_bind($connect, $dn, $password));
        if ($ds = @ldap_bind($connect, $dn, $password)) {
            $filters = "(samaccountname=$handle)";
            //    $filters = "(cn=*)"; // get all results
            $results = ldap_search($connect, "dc=" . ldap_basedn . ",dc=COM", $filters) or exit("unable tosearch");
            $entries = ldap_get_entries($connect, $results);
            if (count($entries) > 0) {
                return $entries;
            } else {
                return 0;
            }

        } else {
            return 0;
        }


    }

Setup IIS server and PHP on window R1,R2 server

Web Platform Installer 5.0 - software  need to install first
---------------------------------

- MySQL windows 5.0
- MS Driver 4.1(x64) for PHP v7.1 for SQLServer in IIS Express
- MS Driver 4.1(x86) for PHP v7.1 for SQLServer in IIS Express
- MS Driver 4.1(x64) for PHP v7.1 for SQLServer in IIS
- MS Driver 4.1(x86) for PHP v7.1 for SQLServer in IIS

- Windows cache extension 2.0(x64) for PHP 7.1 in IIS Express
- Windows cache extension 2.0(x64) for PHP 7.1
- Windows cache extension 2.0(x86) for PHP 7.1 in IIS Express
- Windows cache extension 2.0(x86) for PHP 7.1

- PHP 7.1.1 (x64)
- PHP 7.1.1 (x64) for IIS Express
- PHP 7.1.1 (x86)
- PHP 7.1.1 (x86) for IIS Express

- IIS-web server
- WAS-config-API's
- IIS-HttpCompressionStatic
- IIS-Static
- IIS-DefaultDocument
- IIS-HttpErrors
- IIS-StaticContent
- Windows Azure Pack: Update for service Bus 1.1-.Net Framework 4.6 compatibility..

- MySQL Windows 5.1
- URL Rewrite 2.0
- Microsoft .NET Framework 4.5.2
- Windows Powershell 3.0
- Windows Powershell 3.0
- PHP 5.3.28
- .NET 4.5 for windows 8
- .NET 4.5 Extended with ASP.NET for windows 8
- IIS:CGI

- IIS: WAS Process Model
- IIS: WAS Configuration API
- IIS: Static Content Compression
- IIS: Request Filtering
- IIS: Management Console

- IIS: Request Monitor
- IIS: Logging Tools
- IIS: HTTP Logging

- IIS:  HTTP Errors
- IIS: Directory Browsing
- IIS: DefaultDocument
- IIS: Static Content