Kohana Auth 模块未对密码进行哈希处理
我正在使用 Kohana 2.3.4,但无法使身份验证模块正常工作。
我只是添加一个这样的用户:
$user = ORM::factory('user');
$user->username = 'admin';
$this->auth = Auth::instance();
$user->email = '[email protected]';
$user->password = 'secret';
$user->add(ORM::factory('role', 'login'));
$user->save();
问题是,当我查看用户表时,密码是明文的。 似乎 auth_user_model 没有被调用。
我的用户模型来自文档。即
// and, in models/user.php
class User_Model extends ORM {
protected $has_and_belongs_to_many = array('roles');
public function unique_key($id = NULL)
{
if ( ! empty($id) AND is_string($id) AND ! ctype_digit($id) )
{
return 'username';
}
return parent::unique_key($id);
}
}
仔细检查后,文件 Auth_User_Model 没有被调用。我把它弄坏了,没有得到任何投诉。
所以我改变了
class User_Model extends Auth_User_Model {
,现在它正在对密码进行哈希处理。这是正确的使用方法吗?我很惊讶我没有看到更多关于此的评论? 到
class User_Model extends ORM {
I'm using Kohana 2.3.4 and can't get the auth module to work.
I'm just adding a user like this:
$user = ORM::factory('user');
$user->username = 'admin';
$this->auth = Auth::instance();
$user->email = '[email protected]';
$user->password = 'secret';
$user->add(ORM::factory('role', 'login'));
$user->save();
The problem is that when I look into the users table, the password is in the clear.
It seems like the auth_user_model is not being called.
My user model is from the documentation. i.e.
// and, in models/user.php
class User_Model extends ORM {
protected $has_and_belongs_to_many = array('roles');
public function unique_key($id = NULL)
{
if ( ! empty($id) AND is_string($id) AND ! ctype_digit($id) )
{
return 'username';
}
return parent::unique_key($id);
}
}
On closer inspection the file Auth_User_Model isn't being called. I corrupted it and got no complaints.
So I changed
class User_Model extends Auth_User_Model {
And now it's hashing the passwords. Is this the correct way to use it? I'm surprised I'm not seeing more comments about this?
To
class User_Model extends ORM {
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是将用户模型与 ORM Auth 驱动程序一起使用的正确方法。您还可以在自己的模型中重载 __set() 并像 auth_user_model 一样进行操作。
Yes, that's the proper way to use your user model with the ORM Auth driver. You could also overload __set() in your own model and do it like the auth_user_model.