<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>

CC BY-SA 3.0
2016-03-17T23:14:32.580Z
Past @carlcs, you are a genius!
Lindsey D
CC BY-SA 3.0
2018-04-23T20:52:58.923Z
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`
Sam Hernandez
CC BY-SA 3.0
2018-04-24T07:47:27.030Z
@SamHernandez ooh nice!
carlcs
CC BY-SA 4.0
2018-08-15T18:43:26.960Z
I come back to this answer with embarrassing frequency.
Patrick Harrington
CC BY-SA 4.0
2018-12-18T15:45:15.387Z
@PatrickHarrington you are not alone my friend
stojda
CC BY-SA 4.0
2019-12-13T20:32:03.073Z
The code to generate the example passwords table above is here: https://gist.github.com/lukeholder/ef09a0e667d864d73244bcd83816ca99
Luke Holder
CC BY-SA 4.0
2020-02-18T20:03:30.737Z
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?
CreateSean
CC BY-SA 4.0
2020-06-12T11:51:53.897Z
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!
Rohan
CC BY-SA 4.0
2020-08-20T04:47:45.993Z
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.
neekster
CC BY-SA 4.0
2021-12-22T00:14:31.790Z
1st time comment-or, 5th time user. Hat's off.
Jeff Irwin
CC BY-SA 4.0
2022-02-11T09:53:33.767Z
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.
solarise
CC BY-SA 4.0
2016-03-01T17:09:20.307Z
2022-03-04T14:45:42.653Z
2022-03-04T14:45:42.653Z
carlcs
<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>

CC BY-SA 4.0
2023-11-10T06:49:08.790Z
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.
Keith John Hutchison
CC BY-SA 4.0
2023-11-10T06:50:20.280Z
As at 2023-11-10 there is an online bcrypt generator https://bcrypt.online/
Keith John Hutchison
CC BY-SA 4.0
2018-12-19T19:31:11.793Z
2018-12-19T19:31:11.793Z
tjbp
<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>

CC BY-SA 4.0
2024-05-18T19:32:30.600Z
2024-05-18T19:32:30.600Z
kmgdev
<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>

CC BY-SA 4.0
2024-10-17T07:19:40.440Z
2024-10-17T07:19:40.440Z
Frank Lämmer
<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>

CC BY-SA 3.0
2016-02-19T12:57:20.287Z
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?
bravokiloecho
CC BY-SA 3.0
2016-02-19T13:07:23.780Z
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 :)
chris
CC BY-SA 3.0
2016-02-19T17:38:34.580Z
Just in case anyone else needs to do this, I made a plugin here: https://github.com/bravokiloecho/craft-password-helper
bravokiloecho
CC BY-SA 4.0
2018-12-19T19:49:45.597Z
This tweet shows you how to reset the password to `secret` -> https://twitter.com/nystudio107/status/1063135843441954816
andrew.welch
CC BY-SA 3.0
2016-02-19T12:49:20.007Z
2016-02-19T12:49:20.007Z
chris
<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>

<password><mysql>
Reset password with MySQL
# 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/bravokiloecho/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 @chris' 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 @carlcs, 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**: @SamHernandez ooh nice!  
> **username_4**: I come back to this answer with embarrassing frequency.  
> **username_5**: @PatrickHarrington you are not alone my friend  
> **username_6**: The code to generate the example passwords table above is here: https://gist.github.com/lukeholder/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 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 [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.


---

