Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+7 votes
15.1k views
in Q2A Core by
Basically, I forgot the admin's user password so I'm not able to log in to reset it. Additionally, I'm not able to reset it via the forgot password feature as I'm still setting up the site and the mailing system is not working.

How can I reset a user's password directly from the database?

2 Answers

+15 votes
by
edited by
 
Best answer

Up to Q2A v1.7.4 this was the only way:

I ended up running the following update on the database:

UPDATE qa_users
SET passcheck = UNHEX(SHA1(CONCAT(LEFT(passsalt, 8), 'new_pass', RIGHT(passsalt, 8))))
WHERE userid = 1;

Replace 1 with the user's id and new_pass with the new password for the user.


As of Q2A v1.8 things have changed. This should be the approach to use:

1. Get the password from the PHP function password_hash (you could use a PHP online IDE to do so quickly):

echo password_hash('new_pass', 1);

That should return an awful string. For example, after hashing password P@5sWoRd you should get something like this $2y$10$xkK9WkpgacLrE4kakOZFmO/1SxLWq6BvJYSjAC1GAZnKShSQbjm.O​

2. Once you have the hashed password run the following query:

UPDATE qa_users
SET passhash = 'hashed_password'
WHERE userid = 1;

Replace 1 with the user's id and hashed_password with the hashed password generated in the previous step.

by
+1
This is an interesting report. It is more secure than creating a back door.
0 votes
by

Changing the password of an admin from the database involves accessing the database and updating the admin user's password field with a new value. The specific steps to do this may vary depending on the database management system you are using, but here is a general outline of the process:

  1. Log in to your database management system (e.g. phpMyAdmin, MySQL Workbench, etc.) with your admin credentials.
  2. Locate the table that contains your admin user's information. This table may be named "users" or something similar.
  3. Find the row that corresponds to your admin user and locate the password field. The password field is typically stored in a hashed format for security purposes.
  4. Generate a new password for your admin user and hash it using the same algorithm and settings as the original password.
  5. Update the password field for your admin user with the new hashed password value.
  6. Save the changes to the database and log out of the database management system.

It's important to note that directly editing the database can be risky and may cause unintended consequences. It's recommended to have a backup of your database before making any changes, and to use caution when making modifications to ensure that your data remains intact and secure. Additionally, it's a good practice to use a secure password and to store passwords in a hashed format to protect against unauthorized access.

...