<p>Given a list of <code>elements/User</code> that you want to get the password reset URL for, you can loop through them and call this for each one:</p>

<pre><code>$url = Craft::$app-&gt;getUsers()-&gt;getPasswordResetUrl($user)'
</code></pre>

CC BY-SA 4.0
2019-11-18T10:56:10.917Z
Hi, I wanted to do this in a template. I've discovered that the password reset link is a combination of the "uid" and a code: 
`/actions/users/set-password?code=<code>&id=<uid>`. I can fetch the uid with the following code: `{% set users = craft.users().status(null).addSelect(['users.uid']).all() %}`, but where does this "code" come from?
outline4
CC BY-SA 4.0
2019-11-18T11:22:06.353Z
I am sorry... I've discovered that you can use: `{{ craft.app.getUsers.getPasswordResetUrl(user) }}`. Works like a charm! Thanks!
outline4
CC BY-SA 4.0
2019-11-15T22:21:02.247Z
2019-11-15T22:21:02.247Z
Brad Bell
<p>We are migrating users from a e-commerce site to a new craft commerce 2.x site. </p>

<p>Apparently it's a little too confusing for our customers to use the "forgot password" link to obtain a new password. </p>

<p>So our idea was to send them an email with their username and a link where they can directly set their password. </p>

<p>e.g. "user1", "<a href="https://mysite.com/actions/users/set-password?code=qwaZDk6mSa0tbnLBx8U4WkTnTBclK1ZZ&amp;id=779e05ca-5c39-4f66-a56c-9a431bd0b355" rel="nofollow noreferrer">https://mysite.com/actions/users/set-password?code=qwaZDk6mSa0tbnLBx8U4WkTnTBclK1ZZ&amp;id=779e05ca-5c39-4f66-a56c-9a431bd0b355</a>"</p>

<p>Is it possible to obtain these links programmatically. </p>

<p>We have about 800 users, so copy/pasting them would be very tedious. </p>

<p>any hints? </p>

<p>Cheers<br>
Stefan</p>

<users><password>
How to extract a list of "copy password reset urls" for all users?
# How to extract a list of "copy password reset urls" for all users?

(Asked by: username_0 on 2019-11-15)

We are migrating users from a e-commerce site to a new craft commerce 2.x site.

Apparently it's a little too confusing for our customers to use the "forgot password" link to obtain a new password.

So our idea was to send them an email with their username and a link where they can directly set their password.

e.g. "user1", "<https://mysite.com/actions/users/set-password?code=qwaZDk6mSa0tbnLBx8U4WkTnTBclK1ZZ&id=779e05ca-5c39-4f66-a56c-9a431bd0b355>"

Is it possible to obtain these links programmatically.

We have about 800 users, so copy/pasting them would be very tedious.

any hints?

Cheers  
Stefan

**Tags:** users, password


---

## 1 answers

### Answer by username_1 on 2019-11-15. Score: 0 | Accepted answer

Given a list of elements/User that you want to get the password reset URL for, you can loop through them and call this for each one:
$url = Craft::$app->getUsers()->getPasswordResetUrl($user)'

> **Comments:**
> **username_0**: Hi, I wanted to do this in a template. I've discovered that the password reset link is a combination of the "uid" and a code:  `/actions/users/set-password?code=<code>&id=<uid>`. I can fetch the uid with the following code: `{% set users = craft.users().status(null).addSelect(['users.uid']).all() %}`, but where does this "code" come from?  
> **username_0**: I am sorry... I've discovered that you can use: `{{ craft.app.getUsers.getPasswordResetUrl(user) }}`. Works like a charm! Thanks!  

---

