[英]Using email instead of username in CakePHP's Auth Component
CakePHP's Auth component requires the username field to be present in order to convert the password field into a hash upon save. CakePHP的Auth组件要求提供用户名字段,以便在保存时将密码字段转换为哈希值。 Apparently, even if I put the following in the
beforeFilter()
: 显然,即使我将以下内容放入
beforeFilter()
:
$this->Auth->fields = array('username' => 'email', 'password' => 'password');
it doesn't encrypt the password before inserting it into the database. 在将密码插入数据库之前,它不会对密码进行加密。
So my question is, assuming this is supposed to happen, what is the best way to encrypt the password? 所以我的问题是,假设这应该发生,那么加密密码的最佳方法是什么? Or, have I made a simple error somewhere?
还是我在某个地方犯了一个简单的错误?
Thanks in advance for any assistance! 在此先感谢您的协助!
Here's the before filter in the users_controller.php: 这是users_controller.php中的before过滤器:
function beforeFilter() {
$this->Auth->fields = array('username' => 'email', 'password' => 'password');
}
And the app_controller.php: 和app_controller.php:
var $components = array('Auth');
Oops, I had duplicated the line $this->Auth->fields = array('username' => 'email', 'password' => 'password');
糟糕,我已复制了
$this->Auth->fields = array('username' => 'email', 'password' => 'password');
in the AppController
as well and it seems that was causing the problem. 在
AppController
中也是如此,这似乎是导致问题的原因。 Sorry about that and thanks for the tip to double check by posting here :) 对此感到抱歉,感谢您通过在此处发帖进行仔细检查的提示:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.