Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I save an automatically generated password in CakePHP?
    text
    copied!<p>I am trying to automatically register users. You enter an email address and it sends the user a password. Sounds simple enough, right? Here are a bunch of things that I've tried in my add action, but none of them work (as indicated).</p> <pre><code>if (!empty($this-&gt;data)) { $this-&gt;User-&gt;create(); $random_pass = $this-&gt;Auth-&gt;password($this-&gt;generatePassword()); // Doesn't work: $user_data['User'] = $this-&gt;data['User']; $user_data['User']['password'] = $random_pass; if ($this-&gt;User-&gt;save($user_data)) { /* ... */ } // Doesn't work: $this-&gt;User-&gt;set('password', $random_pass); if ($this-&gt;User-&gt;save($this-&gt;data)) { /* ... */ } // Doesn't work: $this-&gt;data['User']['password'] = $random_pass; if ($this-&gt;User-&gt;save($this-&gt;data)) { /* ... */ } // Doesn't work: $this-&gt;data['User'][0]['password'] = $random_pass; if ($this-&gt;User-&gt;saveAll($this-&gt;data)) { /* ... */ } } </code></pre> <p>According to <a href="https://stackoverflow.com/questions/960415/cakephp-password-field-is-empty">Why is the CakePHP password field is empty when trying to access it using $this-&gt;data?</a> it's because the Auth component is removing the password. Seems common enough, no? So how do I get around it?</p> <p><strong>More information</strong></p> <p>I'm using <a href="http://bakery.cakephp.org/articles/ashevat/2010/03/12/how-to-implament-one-time-password-for-forgot-my-password-and-account-activation-processes" rel="nofollow noreferrer">this function</a> to generate the password. The add view only has three fields, first_name, last_name, and email (which is assigned to the username field in the Auth component).</p>
 

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