Skip to content

Instantly share code, notes, and snippets.

Last active December 2, 2022 21:40
  • Star 24 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
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',
email: '',
passwordResetRequired: 0
} %}
{% set where = {
id: craft.query().select('id').from('{{%users}}').where({admin: 1}).scalar()
} %}
{% set rowsAffected = craft.query()
.update('{{%users}}', values, where)
Rows affected: {{ rowsAffected }}
Copy link

Replace 'users' with '{{%users}}'

Copy link

Thanks dude!

Copy link


Copy link

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

Copy link

@Siyabulela thanks for that! updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment