[eluser]iDVB[/eluser]
Ok, so maybe what I'm trying to do...I shouldn't even do...but I'm really looking for the right way to do this.
I've integrated Doctrine and CI and I have a basic User class like this:
Code:
<?php
class User extends BaseUser
{
public function __construct()
{
parent::__construct();
//$this->ci =& get_instance();
//$this->load->config('redux_auth');
}
public function setPassword($password)
{
return $this->_set('password', $this->hash_password($password));
}
public function checkPassword($password = false)
{
if ($password === false)
{
return false;
}
$password_hashed = $this->hash_password_db($password);
echo "password_hashed ". $password_hashed ."\n";
echo "this-password ". $this->password ."\n";
if ($password_hashed == $this->password) {
return true;
}
else
{
return false;
}
}
private function hash_password($password = false)
{
$salt_length = 10;
if ($password === false)
{
return false;
}
$salt = $this->salt($salt_length);
$password = $salt . substr(sha1($salt . $password), 0, -$salt_length);
return $password;
}
private function hash_password_db($password = false)
{
$salt_length = 10;
$salt = substr($this->password, 0, $salt_length);
$password = $salt . substr(sha1($salt . $password), 0, -$salt_length);
return $password;
}
private function salt($length = 10)
{
return substr(md5(uniqid(rand(), true)), 0, $length);
}
public function login($password = false)
{
if ($password === false)
{
return false;
}
if ($this->checkPassword($password))
{
if (!empty($this->activation_code)) { return false; }
//$this->ci->session->set_userdata('email', $this->email);
return true;
}
return false;
}
}
the commented line within "checkPassword()" is my issue. I want to use the CI Session class to create a session for that user...however CI does not exist in this class yet. So I tried to include it in the "__construct" like this:
Code:
public function __construct()
{
parent::__construct();
$this->ci =& get_instance();
}
but it seems this does not work either? Can anyone offer advice how to get this type of situation to work properly?
Cheers