I've been given the files to a Drupal site so I can create a new theme. I haven't, however, been given the Drupal admin user/password date so I can't sign in to the admin area. Is there a way I can create a new user directly in the database or some other way?
7 Answers
You can create a new user by added a row to the users table. The password field must contain an MD5 hashed password. You can use online MD5 generators or, if you are using PHPMyAdmin, select the MD5 function next to the textbox where you enter your plain password. Take note of the user id (uid) of your newly created user. After that, you need to find a role that has sufficient permissions in the role table. Find the role id (rid) and enter the uid and rid in a new row in the users_roles table.
If there is no role that gives administrator access, because the client does everything with user 1, you need to perform a slightly dirtier trick. Save the password hash of user 1 somewhere and temporarily add a new password for user 1. Then log in with user 1, create a new account for yourself, a new role with sufficient permissions and add yourself to that role. After that, edit user 1 in the database and restore the password. I can recommend admin role to force a role to have all permissions at all times.
There's a much easier way.
- Go into the DB and change the email address field of the user with id 1 and set it to your email address.
- Go to
http://mysite/user
and click on the password recovery link. - Enter your email address and you'll get a password recovery link.
Of course this assumes that your dev systems allows drupal to send mails out of the box. This is true for most linux and osx boxes but not for Windows.
-
1This is really easier. Once done this, the OP can create a new user, and set back the email for the user #1 as it was before, if it is really necessary.– avpaderno ♦Commented Jun 26, 2012 at 11:46
-
1Even easier would be to use
drush uli
to log in as user 1.– mbomb007Commented Dec 11, 2018 at 20:33
If you have access to the database, run the following query
UPDATE users
SET name='admin',
pass='$S$Drl0vgZ9yuU9uc4JyaTMHxMPriC7q/PsOUOx52fCrVQSTpI/Tu4x',
status=1
WHERE uid = 1;
the login details will be:
username = admin
password = drupal
REFERENCED HERE:
https://knackforge.com/blog/sivaji/different-ways-reset-drupal-admin-password
-
+1 upvote thank you - specifically, for the encrypted
drupal
password, which in my situation I used for Drupal 8 and following these steps. enzo.weknowinc.com/articles/2014/12/07/… Also remember to reset the login attempts by clearing the flood table: drupal.stackexchange.com/a/15447 Commented Dec 28, 2020 at 12:49
You can also create users and assign roles with Drush, as well as change passwords for existing users.
Drush is a command line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend some of our working hours hacking away at the command prompt.
-
1
What you could do is to go into the database, save the old admin password, reset the admin password and then log in, create a new user, and then reset the admin password back to what it was before you started.
If you have access to drush, you could do this:
cd <drupal root directory>
php scripts/password-hash.sh 'drupal'
then take the MD5 hashed password generated above, and:
drush sql-cli
update users set name='admin', pass='pasted_big_hash_from_above' where uid=1;
quit
That should do the trick.
(source)
$user = array();
$user['status'] = 1; //for active user
$user['mail'] = '[email protected]';
//profile field $user['profile_field_fname'] = 'Vikrant';
$user_account = array();
if($user_uid = module_name_get_uid_by_email($user['mail'])) { //It will use for update.
$user_account = user_load(array(uid => $user_uid));
}
//save or update user information.
user_save($user_account, $user);
//Check existing record by email.
function module_name_get_uid_by_email($email){
$query = db_query("SELECT uid FROM {users} WHERE mail = '%s'",$email);
$result = db_fetch_object($query);
return $result->uid;
}
Try the above code.
If you happen to use drush you can use drush upwd [user] --password="[newpassword]"
which (re)sets the password for the user with the specified name. (upwd
is the short command version for user-password
)
Example from drush: drush user-password someuser --password="correct horse battery staple"
which sets the specified password for username "someuser".