website/docs/users-sources/user/password_reset_on_login.mdx
You can require users to reset their password on their next login, using expression policies, custom stages, and a custom user attribute. This guide explains how to configure this with the default-authentication-flow; however, the same steps apply to any authentication flow.
Configuring forced password reset on next login involves the following steps:
1. Creating two expression policies.
2. Creating and binding two stages to the active authentication flow.
3. Binding the expression policies to the stages.
4. Setting a custom user attribute which triggers the password prompt.
You'll need to create two expression policies; one that checks the value of a custom user attribute on the user account attempting to log in, and another that resets the value of the custom user attribute.
Log in to authentik as an administrator and open the authentik Admin interface.
Navigate to Customization > Policies and click Create to set up the first policy.
Select Expression Policy as the policy type, click Next, and configure the following settings:
Name: Provide a descriptive name for the policy (e.g. reset_password_check).
Expression:
# Check if the "reset_password" attribute set to true for the pending user
if request.context["pending_user"].attributes.get("reset_password") == True:
return True
return False
Click Finish to save the first policy, then repeat the steps to create the second policy using the following settings:
Name: Provide a descriptive name for the policy (e.g. reset_password_update).
Expression:
# Check if the "reset_password" attribute is set to true for the pending user
if request.context["pending_user"].attributes.get("reset_password") == True:
# Reset the "reset_password" attribute to false to prevent forcing a password reset on next login
request.context["pending_user"].attributes["reset_password"] = False
return True
return False
Click Finish.
You'll need to create two stages; a Prompt stage to prompt the user to enter a new password, and a User Write stage to update the user's account with the new password. Both stages will need to be bound to the active authentication flow, typically the default-authentication-flow.
default-authentication-flow.Force Password Reset Prompt Stage).x icon between Available Fields and Selected Fields to clear the selections.default-password-change-field-password and default-password-change-field-password-repeat.x icon between Available Policies and Selected Policies to clear the selections.default-password-change-policy.:::tip Optionally, you can create and add a text field to the prompt stage to inform users that they are required to reset their password. For more details on configuring this, refer to the Prompt Stage documentation. :::
Click Next to create the stage and then configure the following settings for the binding:
25 or any number higher than the default-authentication-password stage order and lower than the default-authentication-mfa-validation stage order.Click Finish to create the binding and repeat the process for the second stage using the following settings:
Force Password Reset User Write Stage).Click Next to create the stage and then configure the following settings for the binding:
26 or any number higher than the Force Password Reset Prompt Stage stage order and lower than the default-authentication-mfa-validation stage order.Click Finish to create the binding.
You will need to bind the previously created policies to the newly created stages. Specifically:
- The `reset_password_check` policy needs to be bound to the `Force Password Reset Prompt Stage`.
- The `reset_password_update` policy needs to be bound to the `Force Password Reset User Write Stage`.
default-authentication-flow.Force Password Reset Prompt Stage to expand it.reset_password_check and click Create.Force Password Reset User Write Stage to expand it.reset_password_update and click Create.To require a user to reset their password on next login, you will need to set a custom user attribute on their account.
reset_password: True
The next time the user logs in, they will be required to reset their password, and the reset_password attribute on their account will be set to False.