【发布时间】:2013-05-09 16:07:52
【问题描述】:
我为具有“用户名”和“密码”的用户提供了一个 mongo db 结构。我正在尝试在 cakephp 登录中使用 Auth,但它似乎对我不起作用。我尝试删除 $this->data 但仍然无效。
我的密码使用 Security::hash($this->data['User']['password'])
if(!empty($this->data))
{
if($this->Auth->login($this->data))
{
echo "yes";
}
else{
echo "no";
}
}
在我的应用控制器中,我有这个:
public $components = array('DebugKit.Toolbar', 'Session', 'Auth' => array(
'loginAction' => array(
'controller' => 'pages',
'action' => 'home'
),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'username', 'password' => 'password')
)
)
));
这是我调试登录方法时的结果:
array(
'User' => array(
'password' => '*****',
'username' => 'test@test.com',
'remember' => '0',
'auto_login' => '0'
)
)
我不知道为什么我不能在 mongodb 中使用 Auth。提前感谢您的帮助。
编辑:
当我尝试取消布局时,它会在页面底部显示一个查询:
db.users.find( {"username":"test@test.com","password":"2fdf49ffc396453960802df8fc2417655d1e8fca"}, [] ).sort( [] ).limit( 1 ).skip( 0 )
我从表单中输入的密码的哈希值与正在查询的哈希值不同。哈希值应为“a2374c309ab7823dcd9b4e21dae7511f7a9c7ec5”。为什么 cakephp 将密码转换为另一个哈希值?
【问题讨论】:
-
您使用的是哪个版本的 CakePHP?
-
在这种情况下,您应该使用
$this->request->data而不是$this->data。 -
我已经试过了。当我这样做时,即使我的密码或用户名错误,它总是会输出“yes”。
-
您可以尝试在登录方法的开头添加
debug($this->request->data);并发布结果吗?这可能会有所帮助。 -
嗨@xgalvin 我修改了这个问题。谢谢
标签: php mongodb cakephp cakephp-2.3