Reset Strapi Admin

Dear great community. i have just strat with strapi and i found it great. i have problem with login admin account. the username and password not working so i try some of the command. lik
npm strapi admin:reset-user-password --email=admin@school.com --password=Gourmet1234

which is not working .
Please help me to get out of this stuck to rest admin password

below is my package .json details

{
  "name": "schoolbackend",
  "private": true,
  "version": "0.1.0",
  "description": "A Strapi application",
  "scripts": {
    "develop": "strapi develop",
    "start": "strapi start",
    "build": "strapi build",
    "strapi": "strapi"
  },
  "devDependencies": {},
  "dependencies": {
    "strapi": "3.6.3",
    "strapi-admin": "3.6.3",
    "strapi-utils": "3.6.3",
    "strapi-plugin-content-type-builder": "3.6.3",
    "strapi-plugin-content-manager": "3.6.3",
    "strapi-plugin-users-permissions": "3.6.3",
    "strapi-plugin-email": "3.6.3",
    "strapi-plugin-upload": "3.6.3",
    "strapi-plugin-i18n": "3.6.3",
    "strapi-connector-bookshelf": "3.6.3",
    "knex": "0.21.18",
    "sqlite3": "5.0.0"
  },
  "author": {
    "name": "A Strapi developer"
  },
  "strapi": {
    "uuid": "9ee57c5d-03ff-4e58-acd1-57a4188029d3"
  },
  "engines": {
    "node": ">=10.16.0 <=14.x.x",
    "npm": "^6.0.0"
  },
  "license": "MIT"
}

Can you provide a bit more information than just “it’s not working”

What specifically isn’t working when you run that command? Any errors? Have you checked the database to see if the hashed value of the password is being changed? Ect

@Raj_kumar_THAPA At root of you project, run this command:

npm run strapi admin:reset-user-password --email=existing@user.com --password=NewPassword

Provide proper values for email and password flags.

After running this command, you’ll be again prompted for some inputs like in the screenshot below.

3 Likes

Thanks @aniket, this worked for me! I forgot the admin password I setup on my dev server and was worried I’d have to scrap my Strapi installation and start over. You saved me hours of work! I will now be saving my new admin password to my LastPass vault :rofl:

After update the password you just have to create build again with command “strapi build”

Hi Everyone here,
I am stuck with the similar issue, and my strapi is hosted on Azure with an external PostgresDB. When I am trying to reset this admin password it is saying that the username is not there or not recognised. Can anyone please suggest me a way where I can recover both, or change both Username and Password for my admin account.

I am also facing the same problem. after running the command

I got the solution by

Step-1:
strapi console

Step-2

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(‘username@username.com’, ‘newpassword’);

1 Like