Answers.Body: <p>Future me, looks like you forgot your password again and locked yourself out of Craft. You also made your way back to this Stack Exchange question with @chris' perfect answer. Good! And to make your life <em>really</em> easy this time around, I've already generated a password/hash combos for you that works:</p>
  <pre><code>|--------------|---------------------------------------------------------------|
  |  *Password*  |                        *Resulting Hash*                       |
  |--------------|---------------------------------------------------------------|
  |  password    | $2y$13$i1fEVeKiboWR/Hx07N9JtuSZj46KNueAg0IgpwL2TId0sXN.oyibC  |
  |--------------|---------------------------------------------------------------|
  |  NewPassword | $2y$13$YA.7RIgllODUDcmQPf/.FuXjOmKJYot5QxpFhhf4og9fdJWsIPWK6  |
  |--------------|---------------------------------------------------------------|
  |  admin       | $2y$13$Nlvh.kEu8FLIITusfjzQgOIIDryqLnJ3TsV/1UINRCFLfVnjJtILK  |
  |--------------|---------------------------------------------------------------|
  </code></pre>
  <p><em><strong>Update:</strong> The hashing algorithm didn’t change in Craft 3, so the above combo still works.</em></p>
  <p><em><strong>Update:</strong> The hashing algorithm didn’t change in Craft 4, so the above combo still works.</em></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-17T23:14:32.580Z
Answers.Text: Past @carlcs, you are a genius!
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-23T20:52:58.923Z
Answers.Text: Craft 3: Drop this in a template to render a new password hash `{{ craft.app.security.hashPassword('NewPassword') }}`  Output: `$2y$13$3hcn0v5fVCFB28GS3HNJfez3.MY/HaJnomkESPsy7cEN/Hx9skjLq`
Answers.UserDisplayName: Sam Hernandez
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-24T07:47:27.030Z
Answers.Text: @SamHernandez ooh nice!
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-15T18:43:26.960Z
Answers.Text: I come back to this answer with embarrassing frequency.
Answers.UserDisplayName: Patrick Harrington
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-18T15:45:15.387Z
Answers.Text: @PatrickHarrington you are not alone my friend
Answers.UserDisplayName: stojda
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-13T20:32:03.073Z
Answers.Text: The code to generate the example passwords table above is here: https://gist.github.com/lukeholder/ef09a0e667d864d73244bcd83816ca99
Answers.UserDisplayName: Luke Holder
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-18T20:03:30.737Z
Answers.Text: Is there a way I could use this to get the password hash of users in a craft 2 site so I can add it to an xml file for import to Craft 3 via feedme?
Answers.UserDisplayName: CreateSean
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-12T11:51:53.897Z
Answers.Text: See these are the kind of people I love. I don't want to know how to generate the damn password, I just want to login into my local version so I can resume work. I will change it later once I log in. Thank you!
Answers.UserDisplayName: Rohan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-20T04:47:45.993Z
Answers.Text: Wish I could vote for this every time I come back and grab this hash. Would be properly embarrassing just how many votes I would have given it now.
Answers.UserDisplayName: neekster
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-22T00:14:31.790Z
Answers.Text: 1st time comment-or, 5th time user. Hat's off.
Answers.UserDisplayName: Jeff Irwin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-11T09:53:33.767Z
Answers.Text: This must be the 50th time I've come back to this answer. It feels like an old friend now, always there for me in times of need.
Answers.UserDisplayName: solarise
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2016-03-01T17:09:20.307Z
Answers.LastActivityDate: 2022-03-04T14:45:42.653Z
Answers.LastEditDate: 2022-03-04T14:45:42.653Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>If you don't want to mess about trying to insert code in the Craft/Yii stack, v3 just calls password_hash():</p>
  
  <pre><code>password_hash($your_password_string, PASSWORD_DEFAULT, ['cost' =&gt; 13]);
  </code></pre>
  
  <p>As a possibly helpful addendum (I was just trying to run the site locally and needed to log in); if you find you still can't login after changing the password via the database and are running PHP locally, it might be because you're accessing via socket and should add this to <code>config/general.php</code>:</p>
  
  <pre><code>'requireUserAgentAndIpForSession' =&gt; false,
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-10T06:49:08.790Z
Answers.Text: I added this `echo password_hash($your_password_string, PASSWORD_DEFAULT, ['cost' => 13]);` to web/index.php; got a password on page reloaad then removed it.
Answers.UserDisplayName: Keith John Hutchison
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-10T06:50:20.280Z
Answers.Text: As at 2023-11-10 there is an online bcrypt generator https://bcrypt.online/
Answers.UserDisplayName: Keith John Hutchison
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-19T19:31:11.793Z
Answers.LastActivityDate: 2018-12-19T19:31:11.793Z
Answers.UserDisplayName: tjbp
Answers.Body: <p>If you have access to craft via the console and you don't need to update via MySQL specifically, try this solution: <a href="https://craftcms.stackexchange.com/a/39728/234">https://craftcms.stackexchange.com/a/39728/234</a></p>
  <p><code>php craft users/set-password my-username --password 1234567890</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-18T19:32:30.600Z
Answers.LastActivityDate: 2024-05-18T19:32:30.600Z
Answers.UserDisplayName: kmgdev
Answers.Body: <p>Shameless plug: We have published a <a href="https://blog.fortrabbit.com/three-ways-to-reset-the-craft-cms-control-panel-password-without-email-access" rel="nofollow noreferrer">blog post</a> highlighting three ways to recover an account password for Craft CMS (craft console, template, mailtrap).</p>
  <p>I second the answer by kmgdev using the craft console as the best alternative. This question is specifically about doing that in MySQL. Most commonly the reason why you may want to do it, is that sendmail (see <a href="https://craftcms.stackexchange.com/questions/27364/sendmail-not-working-on-craft-3">this question</a> as well) is not working, which is pretty standard these days.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-17T07:19:40.440Z
Answers.LastActivityDate: 2024-10-17T07:19:40.440Z
Answers.UserDisplayName: Frank Lämmer
Answers.Body: <p>Craft uses Yii's <a href="http://www.yiiframework.com/doc/api/1.1/CPasswordHelper"><code>CPasswordHelper::hashPassword</code></a> which is a Blowfish hash algorithm, using PHP's <a href="http://php.net/crypt"><code>crypt</code></a> function with a "blowFishHashCost", which is a setting that can be found through <code>craft()-&gt;config-&gt;get('blowfishHashCost')</code></p>
  
  <p>You could use the <a href="https://craftcms.com/classreference/services/SecurityService#hashPassword-detail"><code>SecurityService::hashPassword</code></a> function to generate a new password, echo it, and update it in the DB manually: <code>craft()-&gt;security-&gt;hashPassword('NewPassword');</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-19T12:57:20.287Z
Answers.Text: Thanks! This is really helpful. Is there any way this can be done in a Twig template? Or can the hashPassword function only be called from a plugin?
Answers.UserDisplayName: bravokiloecho
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-19T13:07:23.780Z
Answers.Text: i'd setup a temporary plugin (just the handle; `ResetPlugin.php` with an init function, in the init function you "Dump and Die" (`Craft::dd(SecurityService::hashPassword('test'))`) and after that, you delete it :)
Answers.UserDisplayName: chris
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-19T17:38:34.580Z
Answers.Text: Just in case anyone else needs to do this, I made a plugin here: https://github.com/bravokiloecho/craft-password-helper
Answers.UserDisplayName: bravokiloecho
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-19T19:49:45.597Z
Answers.Text: This tweet shows you how to reset the password to `secret` -> https://twitter.com/nystudio107/status/1063135843441954816
Answers.UserDisplayName: andrew.welch
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-19T12:49:20.007Z
Answers.LastActivityDate: 2016-02-19T12:49:20.007Z
Answers.UserDisplayName: chris
Body: <p>Is there a way to reset an admin account's password by modifying the MySQL directly?</p>
  
  <p>I've found the <code>craft_users</code> table where the hashed password is stored but I don't know how to hash a string so that it will be read correctly by Craft.</p>
  
Tags: <password><mysql>
Title: Reset password with MySQL
ThreadText: # Reset password with MySQL
  
  (Asked by: username_0 on 2016-02-19)
  
  Is there a way to reset an admin account's password by modifying the MySQL directly?
  
  I've found the `craft_users` table where the hashed password is stored but I don't know how to hash a string so that it will be read correctly by Craft.
  
  **Tags:** password, mysql
  
  
  ---
  
  ## 5 answers
  
  ### Answer by username_16 on 2016-02-19. Score: 39 | Accepted answer
  
  Craft uses Yii's [`CPasswordHelper::hashPassword`](http://www.yiiframework.com/doc/api/1.1/CPasswordHelper) which is a Blowfish hash algorithm, using PHP's [`crypt`](http://php.net/crypt) function with a "blowFishHashCost", which is a setting that can be found through `craft()->config->get('blowfishHashCost')`
  
  You could use the [`SecurityService::hashPassword`](https://craftcms.com/classreference/services/SecurityService#hashPassword-detail) function to generate a new password, echo it, and update it in the DB manually: `craft()->security->hashPassword('NewPassword');`
  
  > **Comments:**
  > **username_0**: Thanks! This is really helpful. Is there any way this can be done in a Twig template? Or can the hashPassword function only be called from a plugin?  
  > **username_16**: i'd setup a temporary plugin (just the handle; `ResetPlugin.php` with an init function, in the init function you "Dump and Die" (`Craft::dd(SecurityService::hashPassword('test'))`) and after that, you delete it :)  
  > **username_0**: Just in case anyone else needs to do this, I made a plugin here: https://github.com/username_0/craft-password-helper  
  > **username_17**: This tweet shows you how to reset the password to `secret` -> https://twitter.com/nystudio107/status/1063135843441954816  
  
  ---
  
  ### Answer by username_1 on 2016-03-01. Score: 137
  
  Future me, looks like you forgot your password again and locked yourself out of Craft. You also made your way back to this Stack Exchange question with @username_16' perfect answer. Good! And to make your life *really* easy this time around, I've already generated a password/hash combos for you that works:
  
  ```
  |--------------|---------------------------------------------------------------|
  |  *Password*  |                        *Resulting Hash*                       |
  |--------------|---------------------------------------------------------------|
  |  password    | $2y$13$i1fEVeKiboWR/Hx07N9JtuSZj46KNueAg0IgpwL2TId0sXN.oyibC  |
  |--------------|---------------------------------------------------------------|
  |  NewPassword | $2y$13$YA.7RIgllODUDcmQPf/.FuXjOmKJYot5QxpFhhf4og9fdJWsIPWK6  |
  |--------------|---------------------------------------------------------------|
  |  admin       | $2y$13$Nlvh.kEu8FLIITusfjzQgOIIDryqLnJ3TsV/1UINRCFLfVnjJtILK  |
  |--------------|---------------------------------------------------------------|
  
  ```
  
  ***Update:** The hashing algorithm didn’t change in Craft 3, so the above combo still works.*
  
  ***Update:** The hashing algorithm didn’t change in Craft 4, so the above combo still works.*
  
  > **Comments:**
  > **username_2**: Past @username_1, you are a genius!  
  > **username_3**: Craft 3: Drop this in a template to render a new password hash `{{ craft.app.security.hashPassword('NewPassword') }}`  Output: `$2y$13$3hcn0v5fVCFB28GS3HNJfez3.MY/HaJnomkESPsy7cEN/Hx9skjLq`  
  > **username_1**: @username_3 ooh nice!  
  > **username_4**: I come back to this answer with embarrassing frequency.  
  > **username_5**: @username_4 you are not alone my friend  
  > **username_6**: The code to generate the example passwords table above is here: https://gist.github.com/username_6/ef09a0e667d864d73244bcd83816ca99  
  > **username_7**: Is there a way I could use this to get the password hash of users in a craft 2 site so I can add it to an xml file for import to Craft 3 via feedme?  
  > **username_8**: See these are the kind of people I love. I don't want to know how to generate the damn password, I just want to login into my local version so I can resume work. I will change it later once I log in. Thank you!  
  > **username_9**: Wish I could vote for this every time I come back and grab this hash. Would be properly embarrassing just how many votes I would have given it now.  
  > **username_10**: 1st time comment-or, 5th time user. Hat's off.  
  > **username_11**: This must be the 50th time I've come back to this answer. It feels like an old friend now, always there for me in times of need.  
  
  ---
  
  ### Answer by username_12 on 2018-12-19. Score: 7
  
  If you don't want to mess about trying to insert code in the Craft/Yii stack, v3 just calls password\_hash():
  
  ```
  password_hash($your_password_string, PASSWORD_DEFAULT, ['cost' => 13]);
  
  ```
  
  As a possibly helpful addendum (I was just trying to run the site locally and needed to log in); if you find you still can't login after changing the password via the database and are running PHP locally, it might be because you're accessing via socket and should add this to `config/general.php`:
  
  ```
  'requireUserAgentAndIpForSession' => false,
  
  ```
  
  > **Comments:**
  > **username_13**: I added this `echo password_hash($your_password_string, PASSWORD_DEFAULT, ['cost' => 13]);` to web/index.php; got a password on page reloaad then removed it.  
  > **username_13**: As at 2023-11-10 there is an online bcrypt generator https://bcrypt.online/  
  
  ---
  
  ### Answer by username_14 on 2024-05-18. Score: 2
  
  If you have access to craft via the console and you don't need to update via MySQL specifically, try this solution: <https://craftcms.stackexchange.com/a/39728/234>
  
  `php craft users/set-password my-username --password 1234567890`
  
  
  ---
  
  ### Answer by username_15 on 2024-10-17. Score: 1
  
  Shameless plug: We have published a [blog post](https://blog.fortrabbit.com/three-ways-to-reset-the-craft-cms-control-panel-password-without-email-access) highlighting three ways to recover an account password for Craft CMS (craft console, template, mailtrap).
  
  I second the answer by username_14 using the craft console as the best alternative. This question is specifically about doing that in MySQL. Most commonly the reason why you may want to do it, is that sendmail (see [this question](https://craftcms.stackexchange.com/questions/27364/sendmail-not-working-on-craft-3) as well) is not working, which is pretty standard these days.
  
  
  ---
  
  