For those familiar with the Auth module in Kohana, I can't login a user. I can create a user fine, but apparently the hashes aren't matching. I've used the provide MySql schema to create the db and I'm using the the modules models.
Here's my create a user code:
public function user_create()
{
$user = ORM::factory('user');
$user->username = "user";
$this->auth = Auth::instance();
$user->email = "[email protected]";
$user->password = $this->auth->hash_password('admin');
$user->add(ORM::factory('role', 'login'));
$user->add(ORM::factory('role', 'admin'));
if ($user->save())
{
$this->template->title = "user saved";
$this->template->content = "user saved";
}
}
It creates a user with a hashed password and gives it the proper login/admin roles. Everything looks fine in the DB. Here's my login code. I skipped the begining part that checks if the user is logged in.
$user = $this->input->post('username');
$password = $this->input->post('password');
if(!empty($user))
{
$find_user = ORM::factory('user')->where('username', $user)->find();
$username = $find_user->username;
$this->auth = Auth::instance();
if($this->auth->login($username, $password))
{
$error = "logged in";
}
else
{
$error = "not logged in at all";
}
}
$this->template->content = new View('admin/login_view');
$this->template->content->user_info = $username . " " . $password;
$this->template->title = "Login Admin";
$this->template->content->bind('error', $error);
It always returns "not logged in at all". I verify I entered the correct username and password, but it doesn't log in. I cannot figure out why. I'm using the built in hash_password function to create the password and I've followed the docs, but I can't spot the error. Any help?