Kohana Auth module cannot log in

For those who are familiar with the Auth module in Cohan, I cannot log in. I can create the user in the order, but apparently, the hashes do not match. I used the MySql schema to create db, and I use module models.

Here I create the user code:

    public function user_create()
    {
        $user = ORM::factory('user');
        $user->username = "user";

        $this->auth = Auth::instance();

        $user->email = "info@test.com";
        $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 him the correct login / administrator roles. Everything looks good in the DB. Here is my login code. I skipped the initial part, which 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);

" ". , , . , . hash_password , , . ?

+3
1

Auth kohana , __set(). , , :

public function user_create()
    {
            $user = ORM::factory('user');
            $user->username = "user";

            $this->auth = Auth::instance();

            $user->email = "info@test.com";
            $user->password = 'admin';
...

, . auth (models/auth_user.php), :

public function __set($key, $value)
{
    if ($key === 'password')
    {
        // Use Auth to hash the password
        $value = Auth::instance()->hash_password($value);
    }

    parent::__set($key, $value);
}
+12

Source: https://habr.com/ru/post/1723156/


All Articles