-
Open a console inside the project folder.
-
execute
npx strapi console
command -
Copy & paste this code snippet in the console
function changePassword(useremail, password) { strapi.admin.services.user.findOne({ email: useremail }) .then((u) => { if (u) { strapi.admin.services.auth .hashPassword(password) .then((hashedPassword) => { strapi .query("user", "admin") .update({ id: u.id }, { password: hashedPassword }) .then(() => console.log("Updated successfully.")) .catch((ex) => console.error("Failed to update password.", ex)); }) .catch((ex) => console.error("Failed to hash password and update it.", ex) ); } else { console.error("Wrong email?? Please check your email"); } }); } changePassword("your_admin_user", "your_admin_password");
One line version
function changePassword(useremail, password) { strapi.admin.services.user.findOne({ email: useremail }).then(u => { if (u) { strapi.admin.services.auth.hashPassword(password).then(hashedPassword => { strapi.query('user', 'admin').update({id: u.id }, { password: hashedPassword }).then(() => console.log('Updated successfully.')).catch((ex) => console.error('Failed to update password.', ex)) }).catch(ex => console.error('Failed to hash password and update it.', ex)); } else { console.error('Wrong email?? Please check your email'); } }); } changePassword('your_admin_user', 'your_admin_password');
Last active
April 4, 2021 17:51
-
-
Save juandm/db335e5967d9431f45de5256d7919ebb to your computer and use it in GitHub Desktop.
Recover strapi admin password in development mode
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment