0

我正在使用 Kohana 活动记录,并使用它的类添加用户名及其在用户和角色用户表中的角色,如下所述:

在 DB 中手动添加这些值:

mysql> select *from users;
+----+-------------+----------+----------+--------+------------+
| id | email       | username | password | logins | last_login |
+----+-------------+----------+----------+--------+------------+
|  1 | abc@abc.com | Tito     | password |    123 |       1234 |
+----+-------------+----------+----------+--------+------------+
1 row in set (0.03 sec)

mysql> select * from roles_users;
+---------+---------+
| user_id | role_id |
+---------+---------+
|       1 |       1 |
+---------+---------+
1 row in set (0.03 sec)

// This table and its data are there from default database
mysql> select * from roles;
+----+-------+------------------------------------------------------+
| id | name  | description                                          |
+----+-------+------------------------------------------------------+
|  1 | login | Login privileges, granted after account confirmation |
|  2 | admin | Administrative user, has access to everything.       |
+----+-------+------------------------------------------------------+
2 rows in set (0.01 sec)

现在,当我使用下面提到的代码登录时,它返回 false。

$post =  Auth::instance()->login("Tito", "password");

你能指导我需要做什么吗?

身份验证、数据库、ORM 模块也未注释。

auth.php 文件上下文来自 application/config/auth.php:

return array(

'driver'       => 'file',
'hash_method'  => 'sha256',
'hash_key'     => 'Somebiglonghaskeyofmixedcharacters102345567709',
'lifetime'     => 1209600,
'session_type' => Session::$default,
'session_key'  => 'auth_user',

// Username/password combinations for the Auth File driver
'users' => array(
    // 'admin' => 'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02',
),

);
4

1 回答 1

0

您是否手动在表格中添加密码?您在 table 中添加 pass 之前是否使用了 $auth->hash($password) ?当您尝试登录 kohana 登录方法时,请创建一个散列密码。因此,您无法登录(密码!=哈希(密码))

protected function _login($user, $password, $remember)
{

     ......

    if (is_string($password))
    {
        // Create a hashed password
        $password = $this->hash($password);
    } 
     ......
}
于 2013-02-21T11:24:09.440 回答