/** * 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); //SESSION HERE Yii::app()->session->add('username', UserIdentity::encrypt_decrypt('encrypt', $this->username)); Yii::app()->session->add('password', UserIdentity::encrypt_decrypt('encrypt', $this->password)); return true; } else { return false; } }
public function __construct($username = null, $password = null) { // bind and connect to the server if ($username == null || $password == null) { if (isset($_SESSION['username']) && isset($_SESSION['password'])) { $username = UserIdentity::encrypt_decrypt('decrypt', Yii::app()->session['username']); $password = UserIdentity::encrypt_decrypt('decrypt', Yii::app()->session['password']); } else { throw new LDAPQueryException('Username and/or password missing'); } } $options = Yii::app()->params['ldap']; $this->connection = ldap_connect($options['host']); ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($this->connection, LDAP_OPT_REFERRALS, 0); ldap_start_tls($this->connection); if ($this->connection) { // Note: in general it is bad to hide errors, however we're checking for an error below $this->bind = @ldap_bind($this->connection, "uid={$username},ou={$options['ou']},{$options['base_dn']}", $password); } }