gpt4 book ai didi

authentication - cakephp 3登录问题

转载 作者:行者123 更新时间:2023-12-04 06:38:22 24 4
gpt4 key购买 nike

我已经尝试了所有教程,所有 cakephp3 文档,但我仍然面临登录问题我的代码是:
应用 Controller .php

public function initialize()
{
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authorize'=> 'Controller',//added this line
'authenticate' => [
'Form' => [
'userModel' => 'Users', // Added This
'fields' => [
'username' => 'email',
'password' => 'password'
]
]
],
'loginAction' => [
'controller' => 'Users',
'action' => 'login'
]
]);

$this->Auth->allow(['add']);
}

用户 Controller .php

public function login()
{

if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error('Your username or password is incorrect.');
}

}

模型/实体/User.php

protected $_accessible = [
'*' => true,
'id' => false
];

// ...

protected function _setPassword($password)
{
return (new DefaultPasswordHasher)->hash($password);
}

模型/表/UsersTable.php

class UsersTable extends Table
{

public function validationDefault(Validator $validator)
{
return $validator
->notEmpty('username', 'A username is required')
->notEmpty('password', 'A password is required')
->notEmpty('role', 'A role is required')
->add('role', 'inList', [
'rule' => ['inList', ['admin', 'author']],
'message' => 'Please enter a valid role'
]);
}

}

我在用户表字段中添加了很多用户,包括电子邮件、用户名、密码、角色。
1.当我将数据保存在用户表中时,密码以加密形式保存
2. 当我进入登录表单并输入用户名或密码时,它总是显示错误的用户名或密码
3. 当我打印 $user = $this->Auth->identify(); 时,它总是给我空值。
4. 我不明白这是什么问题。
5. 当我在调试工具包中看到 sql 登录时,它总是显示 '没有事件的数据库连接'
请帮助我

最佳答案

这是一个旧帖子,但我遇到了同样的问题,我找到了解决方案 here .基本上我的密码列(在数据库中)的大小不够大(只有 45 个字符)。这些是之前链接中的原始引用:

Hopefully your password column in the database is big enough :)

关于authentication - cakephp 3登录问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37811446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com