이 자습서 https://book.cakephp.org/3.0/en/tutorials-and-examples/blog-auth-example/auth.html을 따라 등록 양식을 만들었지 만 암호는 암호없이 데이터베이스에 일반 텍스트로 저장됩니다. 제 문제를 해결할 수 있도록 도와주세요. 여기 내 코드입니다 :Cakephp 3에서 암호를 해싱 할 수 없음
Add.ctp
<h1>Register new user </h1>
<div class="users form">
<?= $this->Form->create($user) ?>
<fieldset>
<legend><?= __('Add User') ?></legend>
<?= $this->Form->control('username') ?>
<?= $this->Form->control('password') ?>
</fieldset>
<?= $this->Form->button(__('Submit')); ?>
<?= $this->Form->end() ?>
</div>
법인/User.php
<?php
namespace App\Model\Entity;
use Cake\Auth\DefaultPasswordHasher;
use Cake\ORM\Entity;
class User extends Entity
{
// Make all fields mass assignable except for primary key field "id".
// Make all fields mass assignable for now.
protected $_accessible = ['*' => true];
protected function _setPassword($password) {
return (new DefaultPasswordHasher)->hash($password);
}
// ...
}
?>
UsersTable.php
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Cake\Auth\DefaultPasswordHasher;
class UsersTable extends Table
{
public function validationDefault(Validator $validator)
{
return $validator
->notEmpty('username', 'A username is required')
->notEmpty('password', 'A password is required');
}
}
?>
UsersController.php
<?php
namespace PanelAdmin\Controller;
use Cake\Controller\Controller;
use Cake\ORM\TableRegistry;
use Cake\Event\Event;
class UsersController extends AppController
{
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
$this->Auth->allow('add');
}
public function index()
{
$this->set('users', $this->Users->find('all'));
}
public function view($id)
{
$user = $this->Users->get($id);
$this->set(compact('user'));
}
public function add()
{
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
// Prior to 3.4.0 $this->request->data() was used.
$user = $this->Users->patchEntity($user, $this->request->getData());
//debug($user); die;
if ($this->Users->save($user)) {
$this->Flash->success(__('The user has been saved.'));
return $this->redirect(['action' => 'add']);
}
$this->Flash->error(__('Unable to add the user.'));
}
$this->set('user', $user);
}
}
?>
코드가 잘된 것 같습니다. 업데이트 된 파일을 업로드하고 캐시 파일을 삭제 했습니까? –
@Ofir Baruch : 네, 확신합니다. 내 모델 파일은 아무런 차이가 없으므로 아무 것도 인쇄하지 않기 때문에 디버깅을 호출하지 않는 것 같아요. – user3653474
이 링크를 확인 https://github.com/cakephp/cakephp/issues/3863하지만 아무 것도 작동하지 않습니다 – user3653474