# How to force a user to reset password

**URL:** <https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558>\
**Category:** Get Help\
**Created:** [September 14, 2022, 5:03am UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558 "2022-09-14T05:03:06Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![xbox.user29](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/xbox.user29/32/39909_2.png) [@xbox.user29](https://community.auth0.com/u/xbox.user29)\
**Post date:** [September 14, 2022, 5:03am UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/1 "2022-09-14T05:03:06Z")

</div>

Hello,  
I wanted to ask if somebody has any suggestions or preferably, links, to examples of implementation of the reset password for a user. I am having a hard time implementing what the Change password documentation says, without explicit/specific examples.

Any help would be greatly appreciated.

Regards.

---

<div class="post-metadata">

**Author:** ![pazel](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pazel/32/39897_2.png) [@pazel](https://community.auth0.com/u/pazel)\
**Post date:** [September 14, 2022, 9:22am UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/2 "2022-09-14T09:22:28Z")

</div>

Welcome to Auth0 community,

I am guessing you have already looked at this document. There are multiple ways to reset a user’s password.

> **[Change Users' Passwords](https://auth0.com/docs/authenticate/database-connections/password-change)**
>
> Describes the different ways to reset users' passwords for your Auth0 applications.

Please describe your use case a bit more so I can understand which solution best matches your need.

---

<div class="post-metadata">

**Author:** ![xbox.user29](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/xbox.user29/32/39909_2.png) [@xbox.user29](https://community.auth0.com/u/xbox.user29)\
**Post date:** [September 14, 2022, 3:05pm UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/3 "2022-09-14T15:05:15Z")

</div>

Hello, Thanks for the reply.  
Yes, I already read that document and I see some code there for the backend and already try it without much luck.  
I am using react and node js for my app. I have a button in my admin dashboard for every user already registered on my site/DB.  
When I click that button, I want to force the user to change the password by sending an email notification.  
But like I said I already tried the code on the page that you mentioned, I wanted to know if there are more explicit, step-by-step examples somewhere that might help a bit more…

Regards.

---

<div class="post-metadata">

**Author:** ![pazel](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pazel/32/39897_2.png) [@pazel](https://community.auth0.com/u/pazel)\
**Post date:** [September 14, 2022, 8:37pm UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/4 "2022-09-14T20:37:34Z")

</div>

Thanks, I understand the use case better now.  
So you want to trigger an interactive password reset flow using your NodeJS api.

I think using the Authentication API might be the easiest in this case.

> **[Change Users' Passwords](https://auth0.com/docs/authenticate/database-connections/password-change#authentication-api)**
>
> Describes the different ways to reset users' passwords for your Auth0 applications.

There is already a code snippet provided on the page.

```auto
var axios = require("axios").default;

var options = {
  method: 'POST',
  url: 'https://YOUR_DOMAIN/dbconnections/change_password',
  headers: {'content-type': 'application/json'},
  data: {
    client_id: 'YOUR_CLIENT_ID',
    email: '',
    connection: 'Username-Password-Authentication'
  }
};

axios.request(options).then(function (response) {
  console.log(response.data);
}).catch(function (error) {
  console.error(error);
});

```

If you login to your auth0 account and visit this page it will populate CLIENT\_ID and DOMAIN values from your account automatically.

You need an api that can make a http call like the one above to Auth0 Authentication API

You also need to pass the email address of the user you want to reset the password for from your UI to your NodeJS api.  
Then you can use this email when you send the reset password request to Auth0 Authentication api.

Calling this api will send the user a reset password email and they can follow instructions on how to reset their password.

Also note this flow is not for social logins like Google, Facebook since the passwords are not kept with Auth0 and needs to be reset with provider.

---

<div class="post-metadata">

**Author:** ![xbox.user29](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/xbox.user29/32/39909_2.png) [@xbox.user29](https://community.auth0.com/u/xbox.user29)\
**Post date:** [September 19, 2022, 12:43am UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/5 "2022-09-19T00:43:28Z")

</div>

Thanks again, but like I said I’m struggling to understand how to implement that code. I wanted to know if you know any good examples step by step (maybe videos from somebody else?).  
Regards.

---

<div class="post-metadata">

**Author:** ![kle](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kle/32/50528_2.png) [@kle](https://community.auth0.com/u/kle)\
**Post date:** [September 4, 2023, 9:24pm UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/6 "2023-09-04T21:24:43Z")

</div>

Hi, I was trying to run the snippet on the page, with the curl command I got

> We’ve just sent you an email to reset your password.’

But I have not received the reset email despite me trying multiple times. In the doc there is this line that confuses me

> `Go to Auth0 Dashboard > Applications > Applications, and add the URL to the Allowed Origins (CORS) list.`

what is the URL in this case? Can you add a screenshot of where exactly to paste this URL?  
Thanks

---

<div class="post-metadata">

**Author:** ![tanner.stirrat](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tanner.stirrat/32/42637_2.png) [@tanner.stirrat](https://community.auth0.com/u/tanner.stirrat)\
**Post date:** [April 30, 2024, 4:21pm UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/7 "2024-04-30T16:21:53Z")

</div>

This code uses rules, which are now deprecated. We only want to enforce a password reset on a subset of the users, which means that the community-provided password reset logic doesn’t work for us. How do we go about implementing something similar in an action? Setting the user’s password to the empty string by using the `management.users.update()` function doesn’t work.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [May 22, 2024, 3:29pm UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/9 "2024-05-22T15:29:38Z")

</div>

Hi @xbox.user29, @pazel, @kle, @tanner.stirrat,

You could consider using the built-in [Password Rotation Action](https://marketplace.auth0.com/integrations/auth-0-password-rotation) to force your users to set a new password after a certain number of days.

In the action integration, you will be able to set the **Password Expiry in Days** and **Error Message**.

Let me know if you have any questions.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![tanner.stirrat](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tanner.stirrat/32/42637_2.png) [@tanner.stirrat](https://community.auth0.com/u/tanner.stirrat)\
**Post date:** [May 22, 2024, 4:30pm UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/10 "2024-05-22T16:30:15Z")

</div>

Ruben:

That doesn’t work for our case because the password expiration needs to be conditionally applied. We have different subsets of users with different requirements.

It’d be great if y’all could open-source that action so that people could read and adapt it to their use case.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [May 22, 2024, 5:32pm UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/11 "2024-05-22T17:32:56Z")

</div>

Hi @tanner.stirrat,

Thanks for the update.

If you require the password expiration to be applied conditionally, you might need to write a custom post-login action script to handle this scenario.

Here’s a sample code you can use to adapt to your use case:

```auto
exports.onExecutePostLogin = async (event, api) => {
  // Get the user's last password reset timestamp
 const lastPasswordReset = event.user.last_password_reset;

  // Check if the last password reset timestamp exists
  if (lastPasswordReset) {
    // Convert lastPasswordReset to a Date object
    const lastResetDate = new Date(lastPasswordReset);

    // Get the current date
    const currentDate = new Date();

    // Calculate the difference in days between the current date and the last password reset
    const daysSinceReset = Math.floor((currentDate - lastResetDate) / (1000 * 60 * 60 * 24));

    // Check if it has been more than 30 days since the last password reset
    if (daysSinceReset > 30) {
      try {
        // Force Password Reset
        await requestPasswordChange(event.user.email, event.connection, event.client.client_id);
      } catch (error) {
        console.error('Failed to send password reset email:', error);
      }
      api.access.deny("Please reset your password to continue to the application.");
    }
  } 
};

const axios = require('axios');

async function requestPasswordChange(email, connection, clientId) {
  const url = 'https://{yourDomain}/dbconnections/change_password'; // Replace {yourDomain} with your actual domain
  const payload = {
    email: email,
    connection: connection,
    client_id: clientId
  };

  try {
    const response = await axios.post(url, payload, {
      headers: {
        'Content-Type': 'application/json'
      }
    });
    console.log('Password change request sent');
  } catch (error) {
    console.error(error);
  }
}

```

**Please note that this piece of code is not 100% ready for production and you must test the code to ensure its functionality meets your requirements.**

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![tanner.stirrat](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tanner.stirrat/32/42637_2.png) [@tanner.stirrat](https://community.auth0.com/u/tanner.stirrat)\
**Post date:** [May 22, 2024, 7:44pm UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/12 "2024-05-22T19:44:15Z")

</div>

Rueben:

We’ve already implemented something equivalent using the `node-auth0` lib. The piece I was missing is that I needed to use the `auth0.database.changePassword` function, not `auth0.user.update`. My current issue is that the documentation didn’t really help me get there, and even the snippet you shared doesn’t seem to include authentication credentials - I don’t see the authorization header that would allow a call to Auth0 to succeed. That part isn’t trivial.

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [May 22, 2024, 8:41pm UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/13 "2024-05-22T20:41:09Z")

</div>

Hi @tanner.stirrat,

In the code snippet I shared, you do not need any authorization headers for using the Authentication API’s Change password endpoint. See [this reference](https://auth0.com/docs/api/authentication#change-password).

Have you had the chance to test the code in a [Post-Login Action](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow)?

I have tested it on my end and can confirm that it works. The script will force users to reset their passwords if they have not changed them for more than 30 days.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![tanner.stirrat](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tanner.stirrat/32/42637_2.png) [@tanner.stirrat](https://community.auth0.com/u/tanner.stirrat)\
**Post date:** [May 22, 2024, 9:33pm UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/14 "2024-05-22T21:33:38Z")

</div>

Does that mean the endpoint is unauthenticated, or does that mean that the version of Axios provided by the environment is doing some hidden interceptor patching to provide authentication credentials to the request to the management API?

The former would be concerning from a security perspective. I haven’t seen the latter documented anywhere - is there documentation of that?

---

<div class="post-metadata">

**Author:** ![james.boswell](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@james.boswell](https://community.auth0.com/u/james.boswell)\
**Post date:** [May 23, 2024, 9:40am UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/15 "2024-05-23T09:40:19Z")

</div>

100% agree that it would be super helpful if [Password Rotation](https://marketplace.auth0.com/integrations/auth-0-password-rotation) integration could be added to the existing [open-source Auth0 Market Place repo](https://github.com/auth0/opensource-marketplace)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [June 6, 2024, 9:40am UTC](https://community.auth0.com/t/how-to-force-a-user-to-reset-password/90558/16 "2024-06-06T09:40:56Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
