Last active
December 2, 2022 21:40
-
-
Save samhernandez/1c53b7c75c64f8842fb6da27b9263e9d to your computer and use it in GitHub Desktop.
Craft 3 gain access to admin account for support cases or when owner loses access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# | |
Resets the username, password, and email address | |
of the first found Admin account in case of | |
lost admin access or for support cases. | |
#} | |
{% set values = { | |
username: 'me', | |
password: craft.app.security.hashPassword('mypassword'), | |
email: 'me@site.com', | |
passwordResetRequired: 0 | |
} %} | |
{% set where = { | |
id: craft.query().select('id').from('{{%users}}').where({admin: 1}).scalar() | |
} %} | |
{% set rowsAffected = craft.query() | |
.createCommand() | |
.update('{{%users}}', values, where) | |
.execute() | |
%} | |
Rows affected: {{ rowsAffected }} |
Thanks dude!
THX!
This is great, thanks man. You might wanna add passwordResetRequired: 0
. It didn't work for me until I added that line under email:
. I checked Require a password reset on next login
by mistake
@Siyabulela thanks for that! updated
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace
'users'
with'{{%users}}'