How I am able to create a form/link to let assigned/special users to log-in to the system without entering their username and password?

I want them to be able to use a link/token to login to system instead.

This is mainly for development purpose and I am aware of the security risks on the live website

Thank you in advanced


If security's not a concern (and make sure it really isn't!) then you might as well do it the simplest way possible.

This would involve a small custom module that provides a path to log in users by their ID.

function MYMODULE_menu() {
  $items['insecure-login/%MYMODULE_insecure_login'] = array(
    'title' => 'Insecure login',
    'access callback' => TRUE, // Might as well be, no point in authenticating
    'page callback' => 'MYMODULE_insecure_login',
    'page arguments' => array(1)

  return $items;

function MYMODULE_insecure_login_load($uid) {
  // Don't let user 1 login with this method
  if ($uid == 1) {
    return FALSE;

  // Just return the user ID
  return $uid;

function MYMODULE_insecure_login($uid) {
  if ($account = user_load($uid)) {
    global $user;
    $user->uid = $uid;
    $user->name = $account->name;
    $user->timezone = $account->timezone;

Users will be able to login by visiting http://example.com/insecure-login/USER_ID

I've tested this and it worked, but it felt very wrong. The above code is just a proof of concept if you like, I can't really recommend that you use it.

Please, please double check your thinking before using any method like this; you're obviously aware of the security implications but I can't sign off this post in good conscience without encouraging you to think about it a little more ;)

  • Thank you very much. Yes, this would be only for development as well as educational purpose, and it works great! – Luca Jun 14 '12 at 3:23
  • Was looking for login without password but with any one of the user account field combination with username/email id. For ex date of birth, library id etc.. Is this possible with drupal by overriding login form? (security is not an issue) – kiranking Oct 1 '15 at 6:43

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.