I want to send a one-time-login for all the user accounts.

I am using drush uli which return links similar to http://example.org/user/reset/1/1509979615/VBPx_FMfKeJUEt1moVcsSQGUMX_tFUSYEdEfRlmq7eA which works only for the user account whose ID is 1, not all the user accounts.

How do I pass this URL in Drupal 8?

I just want to know how to use this in the forgot password email.

  • Just replace the http://html with your domain.
    – user21641
    Commented Nov 6, 2017 at 15:37
  • @IvanJaros If the user 5 wants to use one time login, this will be used for only the user 1 right. I want to set one time login for all the users.
    – user78956
    Commented Nov 6, 2017 at 15:43
  • I am not sure about my understanding. How could I use the drush uli in drupal 8. Its confusing!.
    – user78956
    Commented Nov 6, 2017 at 15:44
  • Refer to the docs for uli. drushcommands.com/drush-8x/user/user-login - Other than that, I don't know of a way to trigger mass reset links and email it to everyone offhand. You cannot generate ONE link and use that for everyone because it won't work. Simply changing the id in the url isn't enough. Each user could come to the site and do the forgot password with their email address to get it. As for the domain, you need to set that in config.
    – Kevin
    Commented Nov 6, 2017 at 16:20

4 Answers 4



To get one-time login for the specific user, use this syntax:

drush uli <user>

Where <user> is either uid (e.g. 5), user name, or email address for the user.

To get one-time login URL for multiple users or all, you need to run drush in the loop, e.g.

for uid in $(drush sqlq "SELECT uid FROM users"); do drush uli $uid; done

Run drush help uli for help with syntax.

To correct your http://html part, add -l http://example.com parameter, or set your $base_url in your settings file.

Custom code

If you're interested in sending one-time login via e-mail using Drupal, you can use user_pass_reset_url() function in your custom code.

Generates a unique URL for a user to login and reset their password.

Contrib module

Or use Login one time module (for D8, check this issue).

Login one time provides the ability to email one-time login links to users.

  • I will get a url like $base_url/user/reset/7/1510036033/N5suTv36MbBOMm6rrdZFFZL8TAy9GKgted97zBnu7iQ . I just wanna know that how could use this in forgot password mail.
    – user78956
    Commented Nov 7, 2017 at 6:29
  • @Panda You can use Login one time module for that. Check the updated answer.
    – kenorb
    Commented Nov 7, 2017 at 14:59
  • user_pass_reset_url() is available in D7 too: api.drupal.org/api/drupal/modules!user!user.module/function/… Commented Jan 6, 2022 at 15:39

If you'd like to force all of your users to log in via one-time login links all the time, you could use the passwordless module.

If you set the $base_url in your settings.php file, then the Drush user-login command will generate the correct URL in the output. You could then write a simple script to email every user with their own unique login link.

There is no Drush command to email a password-reset link to a user, but there of course Drupal does this on the request password page. You could use the user module as a guide, and write a simple module or Drush command to mass-reset all users.


In Drush version > 9 it should be

drush uli --name=USERNAME

notice take a look at a digit after reset/{UID}/ is should be the id of user you've tried to reset

in you case user/reset/1/ it obviously reset the password for used one.

So if you want to do it for all user run the following command in your terminal :

for name in $(drush sqlq "SELECT name FROM users"); do drush uli --name=$name; done
drush uli --uid=1

This command would be logged in as an admin because when you set up your site for the first time, the user will be created as an admin role by UID=1.

After that, you will get one-time login URL in your terminal such as


You can paste the URL from /user/..... in your browser after your virtual host or your domain, etc. otherwise you can replace the default value with your domain name.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.