Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You may run into another problem down the road with cakePHP password validation.</p> <p>The problem is that cake hashes passwords first, <em>then</em> does validation, which can cause the input to fail even if it is valid according to your rules. This is why the password is returned to the input field hashed instead of normal.</p> <hr> <p>to fix this, instead of using the special field name 'password', use a different name like 'tmp_pass'. This way, cakePHP Auth won't automatically hash the field.</p> <p>Here's a sample form</p> <pre><code>echo $form-&gt;create('Vendor', array('action' =&gt; 'register')); echo $form-&gt;input('email'); echo $form-&gt;input( 'tmp_pass', array( 'label' =&gt; 'Password','type'=&gt;'password' )); echo $form-&gt;end('Register'); </code></pre> <hr> <p>In your Vendor model, don't assign validation rules to 'password' instead assign these rules to 'tmp_pass', for example</p> <pre><code>var $validate = array('email' =&gt; 'email', 'password' =&gt; ... password rules... ); </code></pre> <p>becomes</p> <pre><code>var $validate = array('email' =&gt; 'email', 'tmp_pass' =&gt; ... password rules... ); </code></pre> <hr> <p>Finally, in your Vendor model, implement beforeSave().</p> <p>First, see if the data validates ('tmp_pass' will be validated against your rules).</p> <p>If successful, manually hash tmp_pass and put it in $this->data['Vendor']['password'] then return true. If unsuccessful, return false.</p> <pre><code>function beforeSave() { if($this-&gt;validates()){ $this-&gt;data['Vendor']['password'] = sha1(Configure::read('Security.salt') . $this-&gt;data['User']['tmp_pass']); return true; } else return false; } </code></pre>
 

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