How to set hashed password for MySQL database user

Sherri Ross

My boss would like me to write a script for our developers to run that would create a new DB user on their dev builds. He does not want me to have the actual password in the code; only the hash. I have the hashed password, but when I try creating a user with that hashed password; it just hashes the hashed password again.

CREATE USER 'test_user1'@'localhost' IDENTIFIED BY 'password'; shows me the hashed password is "*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19"

But if I attempt... CREATE USER 'test_user2'@'localhost' IDENTIFIED BY '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19';

"password" is not actually my password for test_user2.

I have also tried the following UPDATE but "password" still doesn't work for test-user2:

UPDATE `mysql`.`user` SET `authentication_string` = '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' WHERE (`Host` = 'localhost') and (`User` = 'test_user2');

How can I prevent it from hashing the value I'm entering, since I already know the hashed value?

I have also run GRANT SELECT for both users in my testing.

vhu

The key is to use IDENTIFIED WITH mysql_native_password AS 'hash'. Consider the following, for example:

CREATE USER 'jeffrey'@'localhost'
  IDENTIFIED WITH mysql_native_password AS 'hash-goes-here';

Relevant excerpt from the documentation:

IDENTIFIED WITH auth_plugin AS 'auth_string'

Sets the account authentication plugin to auth_plugin and stores the 'auth_string' value as is in the mysql.user account row. If the plugin requires a hashed string, the string is assumed to be already hashed in the format the plugin requires.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I upload a hashed password to my database?

How to update hashed password in laravel?

How to store hashed password in database?

How to create a laravel hashed password

How to store Django hashed password without the User object?

How to set empty string as password for MYSQL database in properties file.

Verifying Hashed Password From MySQL Database

ASP>NET Identity: How to compare a password entered by the user with a hashed password?

How to check a hashed password against database

Verifying a hashed password from database

How to authenticate login with a pre-hashed mysql password in C#?

How to retrieve hashed password from sql database vb.net

How to get the hashed password to pass into my database?

How to set password for MySQL?

How to authenticate user against salted and hashed password and username?

How to store salted hashed password in the database

How to verify an hashed password

How to check mysql hashed password with salt

Flow of validating a user with hashed password?

How do I check if the current password that the user gives in the password reset form matches with the hashed password in Drupal 8

In PHP how to check if hashed password match database password

CakePHP 3 how to edit user without changing password (hashed)

How to match a inputted password to hashed password from database?

MYSQL Database Password Set

How to return hashed password with bcrypt?

How can I set my password for my database user once?

How to get a user's hashed password and hashed salt from firebase authentication onCreate trigger?

How to compare the hashed password with the one stored in the mySql database?

Django Custom User model AbstractBaseUser and Proxy models. Password is not hashed or set properly