12

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?

9

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.

13

There's a much easier way.

  1. Go into the DB and change the email address field of the user with id 1 and set it to your email address.
  2. Go to http://mysite/user and click on the password recovery link.
  3. 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.

  • 1
    This 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. – kiamlaluno Jun 26 '12 at 11:46
  • Even easier would be to use drush uli to log in as user 1. – mbomb007 Dec 11 '18 at 20:33
9

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
    drush help uli – Drupac Jun 26 '12 at 17:24
4

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

2
$user = array();
$user['status'] = 1; //for active user
$user['mail'] = 'test@test.com';
//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.

  • Thanks -- silly question: in what file would I put this code? – Jane Sep 6 '11 at 7:15
2

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".

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.