Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Application with LDAP Authentication
#1
Lightbulb 
(This post was last modified: 03-23-2015, 08:42 PM by rameshfernandez. Edit Reason: To upload sample code and stackoverflow link )

Without codeigniter i am able to connect to ldap_connect but in my codeigniter project i want to embed ldap connectivity also.

the following are the scenarios

1. If the username and email id exist in database then it is connected to ldap using ldap_connect() and get the windows login password and then validate.(Note: the users with username, mail id and windows login password)
2. if username and password exist in database it will be validated and loggedin.(the users with username and no windows login password or mail id)

i did it without codeigniter but here i don't know how to use ldap
Sample code:
PHP Code:
/******LDAP CONNECTIVITY STARTS HERE*********/
$ldaprdn $_POST['uname']; // ldap rdn or dn
 
   $ldappass $_POST['upass']; // associated password
 
   $ldaprdn $_POST['uname'].'@domain.com';
 
   $ldapconn ldap_connect("ip") or die("Could not connect to LDAP server."); //our ip
if ($ldapconn) {
 
   $ldapbind ldap_bind($ldapconn$ldaprdn$ldappass);
 
       // verify binding
 
       if ($ldapbind) {
 
           //echo "<pre>";
 
           //print_r($row_login);
 
           //exit;

 
           $_SESSION['appusername']=$_POST['uname'];
 
           $_SESSION['emp_code']=$row_login['emp_code'];
 
           $_SESSION['emp_id']=$row_login['emp_id'];
 
           $_SESSION['emp_name']=$row_login['emp_name'];
 
           $_SESSION['emp_email']=$row_login['emp_email'];
 
           $_SESSION['emp_dept_id']=$row_login['emp_dept_id'];
 
           $_SESSION['emp_dept_name']=$row_login['dept_name'];
 
           $_SESSION['emp_group']=$row_login['emp_group'];
 
           $_SESSION['emp_category']=$row_login['emp_category'];

 
           $_SESSION['finance_app_authority']=$row_login['finance_approval_status'];
 
           $_SESSION['line_eng_status']=$row_login['line_eng_status'];

 
           $_SESSION['line_name']=$row_login['line_name'];
 
           $_SESSION['dept_name']=$row_login['dept_name'];

 
           if($row_login['emp_mod_status']=='Y'){ //if moderator means
 
               $_SESSION['userType']='MOD';
 
           }
 
           else if($row_login['emp_id']==$row_login['dept_hod_id']){ //if HOD means
 
               $_SESSION['userType']='HOD';
 
           }else{ //if normal user means
 
               $_SESSION['userType']='EMP';
 
           }
 
           echo '<script language="javascript">document.location.href="?p=main&m=it-home"</script>';
 
           exit;

 
       }
 
       else{
 
       echo '<div  class="man_style" style="width:50%;padding:10px 10px 10px 250px !important;text-align:center;color:red;">Invalid password.</div>';
 
       }
 
   
Stackoverflow URL : http://stackoverflow.com/questions/29224...entication
Your help is appreciated
Reply
#2

I don't understand what you mean with
Quote: i don't know how to use ldap


The question is:
can you connect but not authenticate ?
Reply
#3

(03-24-2015, 03:16 AM)sintakonte Wrote: I don't understand what you mean with

Quote: i don't know how to use ldap


The question is:
can you connect but not authenticate ?

All i want is to authenticate user by windows username and password in codeigniter. Suggest me a very simple way please. I tried Auth_Ldap library but it is very complex for me.
Reply
#4

(This post was last modified: 03-24-2015, 06:16 AM by sintakonte.)

the thing is, this isn't a codeigniter problem

you can use the ldap_connect with CI 

and this is my question again
can you connect but not authenticate ?

remove the slashes in your code and see what happens

PHP Code:
if ($ldapbind) {
 
           echo "<pre>";
 
           print_r($row_login);
 
           exit

and show me your CI Code (Controller, Models etc.)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB