Force password reset on next login
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:
- Creating two expression policies.
- Creating and binding two stages to the active authentication flow.
- Binding the expression policies to the stages.
- Setting a custom user attribute which triggers the password prompt.
Create expression policies
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.
Create stages
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.
- Log in to authentik as an administrator and open the authentik Admin interface.
- Navigate to Flows and Stages > Flows and click on the name of the active authentication flow, typically the
default-authentication-flow. - Select the Stage Bindings tab and click Create and bind stage.
- Select Prompt Stage as the stage type, click Next, and configure the following settings for the stage:
- Name: Provide a descriptive name for the stage (e.g.
Force Password Reset Prompt Stage). - Under Fields:
- Click the
xicon between Available Fields and Selected Fields to clear the selections. - Select
default-password-change-field-passwordanddefault-password-change-field-password-repeat.
- Click the
- Under Validation Policies:
- Click the
xicon between Available Policies and Selected Policies to clear the selections. - (Optional but recommended) Select
default-password-change-policy.
- Click the
- Name: Provide a descriptive name for the stage (e.g.
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:
- Order:
25or any number higher than thedefault-authentication-passwordstage order and lower than thedefault-authentication-mfa-validationstage order. - Leave the other settings as their default values.
- Order:
-
Click Finish to create the binding and repeat the process for the second stage using the following settings:
- Stage type: Select User Write Stage as the type.
- Name: Provide a descriptive name for the stage (e.g.
Force Password Reset User Write Stage). - Leave the other settings as their default values.
-
Click Next to create the stage and then configure the following settings for the binding:
- Order:
26or any number higher than theForce Password Reset Prompt Stagestage order and lower than thedefault-authentication-mfa-validationstage order. - Leave the other settings as their default values.
- Order:
-
Click Finish to create the binding.
Bind policies to stages
You will need to bind the previously created policies to the newly created stages. Specifically:
- The
reset_password_checkpolicy needs to be bound to theForce Password Reset Prompt Stage. - The
reset_password_updatepolicy needs to be bound to theForce Password Reset User Write Stage.
- Log in to authentik as an administrator and open the authentik Admin interface.
- Navigate to Flows and Stages > Flows and click on the name of the active authentication flow, typically
default-authentication-flow. - Select the Stage Bindings tab and click the arrow next to the newly created
Force Password Reset Prompt Stageto expand it. - Click Bind existing Policy / Group / User.
- Set Policy to
reset_password_checkand click Create. - Click the arrow next to the newly created
Force Password Reset User Write Stageto expand it. - Click Bind existing Policy / Group / User.
- Set Policy to
reset_password_updateand click Create.
Set custom user attribute
To require a user to reset their password on next login, you will need to set a custom user attribute on their account.
- Log in to authentik as an administrator and open the authentik Admin interface.
- Navigate to Directory > Users and click the Edit icon of the user in question.
- Add the following values to the user's attribute field:
reset_password: True - Click Update.
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.