[solved] ldap problem

i’m using a ldap authetification.

but it doesnt really work as i want.

I found here a documentation for ldap.

ldap

Make it as it was shown in the Doumentation. but it still doesnt work.

now: what i’m doing wrong.

got three pages.

login.php;

LoginForm;php

UserIdentity.php

login.php


<?php

$this->pageTitle=Yii::app()->name . ' - Login';

$this->breadcrumbs=array(

	'Login',

);

?>


<h1>Login</h1>


<p>Bitte füllen Sie das nachfolgende Formular mit den richtigen Daten aus:</p>


<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'login-form',

	'enableAjaxValidation'=>true,

)); ?>


	<p class="note">Felder mit <span class="required">*</span> sind Pflichtfelder!</p>


	<div class="row">

		<?php echo $form->labelEx($model,'username'); ?>

		<?php echo $form->textField($model,'username'); ?>

		<?php echo $form->error($model,'username'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'password'); ?>

		<?php echo $form->passwordField($model,'password'); ?>

		<?php echo $form->error($model,'password'); ?>

		<p class="hint">

			Hint: You may login with <tt>demo/demo</tt> or <tt>admin/admin</tt>.

		</p>

	</div>


	<div class="row rememberMe">

		<?php echo $form->checkBox($model,'rememberMe'); ?>

		<?php echo $form->label($model,'rememberMe'); ?>

		<?php echo $form->error($model,'rememberMe'); ?>

	</div>


	<div class="row buttons">

		<?php echo CHtml::submitButton('Login'); ?>

	</div>


<?php $this->endWidget(); ?>

</div><!-- form -->



LoginForm.php


<?php


/**

 * LoginForm class.

 * LoginForm is the data structure for keeping

 * user login form data. It is used by the 'login' action of 'SiteController'.

 */

class LoginForm extends CFormModel

{

	public $username;

	public $password;

	public $rememberMe;


	private $_identity;


	/**

	 * Declares the validation rules.

	 * The rules state that username and password are required,

	 * and password needs to be authenticated.

	 */

	public function rules()

	{

		return array(

			// username and password are required

			array('username, password', 'required'),

			// rememberMe needs to be a boolean

			array('rememberMe', 'boolean'),

			// password needs to be authenticated

			array('password', 'authenticate', 'skipOnError'=>true),

		);

	}


	/**

	 * Declares attribute labels.

	 */

	public function attributeLabels()

	{

		return array(

			'rememberMe'=>'Login speichern',

		);

	}


	/**

	 * Authenticates the password.

	 * This is the 'authenticate' validator as declared in rules().

	 */

	public function authenticate()

	{

		$this->_identity = new UserIdentity($this->username, $this->password);

		if(!$this->_identity->authenticate())

			$this->addError('password','Incorrect username or password.');

	}


	/**

	 * Logs in the user using the given username and password in the model.

	 * @return boolean whether login is successful

	 */

	public function login()

	{

		if($this->_identity === null)

		{

			$this->_identity = new UserIdentity($this->username,$this->password);

			$this->_identity->authenticate();

		}

		if($this->_identity->errorCode === UserIdentity::ERROR_NONE)

		{

			$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days

			Yii::app()->user->login($this->_identity,$duration);

			return true;

		}

		else

			return false;

	}

}



UserIdentity.php


<?php

Yii::import('application.vendors.*');

require_once 'Zend/Ldap.php';


class UserIdentity extends CUserIdentity

{

	public function authenticate()

	{

		$options = array(

					'host'		=>'hide',

					'username'	=>'hide',

					'password'	=>'hide',

					'baseDn'	=>'hide'

		);

		$ldap = new Zend_Ldap($options);

		try

		{

			$ldap->bind("cn=".$this->username.",hide", $this->password);

			$auth = true;

		} catch (Exception $e)

		{

			$auth = false;

		}

		if ($auth === true)

		{

			$this->errorCode = self::ERROR_NONE;

		}

		return !$this->errorCode;

	}

}

?>

i got also the rigt folders in the right directions.

Plz help me.

First… when you ask for help… please give as many info as you can…

For example… you put all your code and directory listing… but you haven’t written what error do you get…

Anyway I think I found what is wrong:

 ldap.php and exception.php should be in the Zend folder not in the zend/ldap folder

because you use

 require_once 'Zend/Ldap.php';

i’ll try.

my error is, that i’m always getting an error:

"Incorrect username or password."

sry for my forgotten error :(

Now i’m getting another error.

include(Zend_Exception.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory

do i have forget to copy something else?

Got it. copied the wrong Exception file.

so. now i’m getting again the error, that password and username is incorrect… :(

anyone got an idea?

Ok. i now solved my problem.

And it works.

my problem was this line:


$ldap->bind("cn=".$this->username.",hide", $this->password);

i had to change it to:


$ldap->bind("cn=".$this->username.",OU=hide,OU=hide,baseDn", $this->password);