【发布时间】:2015-08-01 03:43:32
【问题描述】:
我正在尝试将登录屏幕放入我的应用程序中。 模型已启动并运行。
现在根据 CakePHP 3.x 食谱,我已将以下内容添加到我的代码中。
// In src/Controller/AppController.php
namespace App\Controller;
use Cake\Controller\Controller;
class AppController extends Controller
{
public function initialize()
{
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
]
]
],
'loginAction' => [
'controller' => 'Users',
'action' => 'login'
]
]);
// Allow the display action so our pages controller
// continues to work.
$this->Auth->allow(['display']);
}
}
//在src/Controller/UsersController.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.');
}
}
在 login.ctp 中
<h1>Login</h1>
<?= $this->Form->create() ?>
<?= $this->Form->input('email') ?>
<?= $this->Form->input('password') ?>
<?= $this->Form->button('Login') ?>
<?= $this->Form->end() ?>
我启动并运行了屏幕。 但后来发现密码需要散列。 mysql数据库中没有。我在我的数据库中使用 sha1 对密码进行了哈希处理。 但是发现cakephp默认使用bcrypt,所以配置了弱“sha1”密码。
但是密码中添加了一个盐值,这使得两个密码不匹配。我该如何解决?
我也可以打开散列功能,在 SO 中找到了一些关于此的链接。但没有一个适用于蛋糕 php 3x。 在文档中,如果我不想使用散列功能,它提到关闭身份验证组件。但我想用它。
干杯,
苏拉夫
【问题讨论】:
-
如何按照手册tutorial 进行操作,该手册还解释了如何使用正确散列的密码创建新用户。
-
Member for 5 years, 2 months请格式化您问题中的代码。 -
@ADmad 感谢您的回复...是的,有效...但正在寻找创建没有哈希的密码...