CakePHP populates password field when creating a new user crash

I get funny behavior with CakePHP in my new user form. This is a pretty simple username, email address and password.

When the user submits and does not fill out the form, he looks like this:

http://imgur.com/fcpS5.png

Of course, creating a new user fails because the password and email fields are empty. When form errors are displayed, it looks like this:

http://imgur.com/Za9C4.png

I'm not sure why the password field is magically filled with text. Shouldn't be empty?

+3
source share
5 answers

"" , "newPassword", . - (, ..) , beforeSave():

function beforeSave() {
    parent::beforeSave();
    if (isset($this->data[$this->name]['newPassword']) && !empty($this->data[$this->name]['newPassword']))
        $this->data[$this->name]['password'] = Security::hash($this->data[$this->name]['newPassword'], 'sha256', true);
    return true;
}
+3

, .

, Auth $this- > data. , , , , $this- > data ['User'] ['password'] , .

+2

, sha1($_POST['password']), , $_POST['password'] , sha1('').

CakePHP, preffiling password, .

+2

, AuthComponent, User , :

$this->Auth->authenticate = $this->User;

, , :

function hashPasswords($data) {
    // do nothing
    return $data;
}

, , , , .

: http://teknoid.wordpress.com/2008/10/08/demystifying-auth-features-in-cakephp-12/

+2

, ( , Auth, - ) - .

, *** ( ), "".

IE:

<?php
    ...
    echo $form->input( 'User.password', array(
        'type' => 'password',
        'value' => ''
    ));
    ...
?>

, , .

+2

Source: https://habr.com/ru/post/1729850/


All Articles