Note that there are some explanatory texts on larger screens.

plurals
  1. POHashing password when adding new user
    primarykey
    data
    text
    <p>CakePHP 2.4</p> <p>While adding a new user I must hash passwords before storing it in the Database. To do so I did:</p> <pre><code>//UsersController public $helpers = array('Html', 'Form'); public $components = array( 'Session', 'Auth' =&gt; array( 'loginRedirect' =&gt; array('controller' =&gt; 'users', 'action' =&gt; 'home', 'home'), 'logoutRedirect' =&gt; array('controller' =&gt; 'users', 'action' =&gt; 'logout') ) ); public function add(){ if($this-&gt;request-&gt;is('post')){ $this-&gt;User-&gt;create(); if($this-&gt;User-&gt;save($this-&gt;request-&gt;data)){ $this-&gt;Session-&gt;setFlash('Saved!'); } } } //UserModel public function beforeSave(){ if(isset($this-&gt;data[$this-&gt;alias]['password'])) $this-&gt;data[$this-&gt;alias]['password'] = md5($this-&gt;data[$this-&gt;alias]['password']); return true; } //add.ctp echo $this-&gt;Form-&gt;create(); echo $this-&gt;Form-&gt;input('text', array('label'=&gt;'Username', 'name'=&gt;'username')); echo $this-&gt;Form-&gt;input('text', array('label'=&gt;'Full name', 'name'=&gt;'fullname')); echo $this-&gt;Form-&gt;input('password', array('label'=&gt;'Password', 'name'=&gt;'password')); echo $this-&gt;Form-&gt;input('text', array('label'=&gt;'Password hint', 'name'=&gt;'pass_hint')); echo $this-&gt;Form-&gt;input('text', array('label'=&gt;'Email', 'name'=&gt;'email')); echo $this-&gt;Form-&gt;input('text', array('label'=&gt;'Contact', 'name'=&gt;'cell')); echo $this-&gt;Form-&gt;end('Create account'); </code></pre> <p>But the thing is passwords are being stored without being hashed!</p> <p>Thanks in advance...</p> <p><strong>Update:</strong> Changed view code to</p> <pre><code>echo $this-&gt;Form-&gt;create('User'); echo $this-&gt;Form-&gt;input('username', array('label'=&gt;'Username')); echo $this-&gt;Form-&gt;input('fullname', array('label'=&gt;'Full name')); echo $this-&gt;Form-&gt;input('pwd', array('label'=&gt;'Password', 'type'=&gt;'password')); echo $this-&gt;Form-&gt;input('pass_hint', array('label'=&gt;'Password hint')); echo $this-&gt;Form-&gt;input('email', array('label'=&gt;'Email')); echo $this-&gt;Form-&gt;input('cell', array('label'=&gt;'Contact')); echo $this-&gt;Form-&gt;end('Create account'); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload