Restoring an Admin User
You might accidentally lost access to an important admin user (or the only admin in the server) and need to restore it without using another admin user. This guide will help you in this process.
Note: To do this, you will need access to the database

Finding the database

Docker based installations

Open Mongo shell within Mongo container
Change into docker-compose directory (where your docker-compose.yml is located):
cd /opt/docker/Rocket.Chat
docker-compose run mongo bash
or run
docker exec -it -u root mongo-image /bin/bash
Make sure to replace mongo with your MongoDB container name in case you use a different one.
Login to mongo shell using :
On the Mongo shell:
use rocketchat
Make sure to replace rocketchat with your actual Mongo database. If you're not sure how it's called either check your docker-compose.yml file or run:
show dbs

Ubuntu Snaps

Connect to MongoDB:
sudo rocketchat-server.mongo
Select Rocket.Chat Database:
use parties

Updating the admin password

Use the below functions to create or update the admin password.
To update the admin password
You can either use a one time access token (that will require the user to change his password):
db.getCollection('users').update({username:"administrator"}, {$set: { "services":{"loginToken":{"token":"some-token-id-that-you-will-use-to-login-once"}}, "requirePasswordChange":true} })
Then access http://{your server url}/login-token/some-token-id-that-you-will-use-to-login-once to login
or you can update the admin password to 12345
db.getCollection('users').update({username:"administrator"}, { $set: {"services" : { "password" : {"bcrypt" : "$2a$10$n9CM8OgInDlwpvjLKLPML.eizXIzLlRtgCh3GRLafOdR9ldAUh/KG" } } } })
Replace administrator with the admin username in question.
Make sure to restart your application container in case the new password is not accepted yet.
To generate a valid admin password
Install bcrypt-cli with:
// npm install -g @carsondarling/bcrypt-cli
Then use this to generate your bcrypt password:
// npm install -g @carsondarling/bcrypt-cli bcrypt $(echo -n "yourPasswordHere" | sha256sum | cut -d " " -f 1) && echo

Reset user role to "admin"

db.users.update({username: "administrator"}, { $push: { roles: "admin"}})
Again, make sure to replace administrator with the admin username in question.