The Change Password script implements the defined function to change the specified user’s password in the external database. We recommend naming this functionDocumentation Index
Fetch the complete documentation index at: https://docs-staging.auth0-mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
changePassword.
The script is used only in a legacy authentication scenario and is required if you want to change a user’s password in the external database. It will execute when a user performs a password reset workflow, or when a password change workflow is started from the or the Auth0 .
ChangePassword function
ThechangePassword function should:
- Update the user’s password in the external database.
- Return
true(or an object containing thelast_password_resetproperty) if the password change operation succeeded. If thelast_password_resetproperty is present in the object, it will be updated on the user’s profile. - Return
falseif the password change operation failed. - Return an error if the external database could not be reached.
Definition
ThechangePassword function accepts three parameters and returns a callback function:
| Parameter | Type | Description |
|---|---|---|
email | String | User’s email address in Auth0 and external database. |
newPassword | String | Value to be set as user’s new password in the external database. This value is sent as plaintext to the function and should be encrypted before being sent to the external database. |
callback | Function | Used to pass data or operation result data through the pipeline. |
Example
This is a pseudo-JavaScript example of how you could implement thechangePassword function. For language-specific examples, read Language-specific script examples.
Encryption
To prevent any potential data leak, encrypt the password value using a cryptographic hash encryption library such asbcrypt.
Example
Callback function
Thecallback function accepts two parameters and is used to pass error data or indicate the result of the operation.
Definition
| Parameter | Type | Required | Description |
|---|---|---|---|
error | Object | Required | Contains error data. |
operationResult | Boolean | Optional | Indicates the result of the change password operation. |
resultObj | Object | Optional | Indicates that the change password operation succeeded. If the last_password_reset property is present, it will be updated on the user’s profile. |
Return a success
If the change password operation succeeded, return thecallback function, and pass a null value as the error parameter and a true value as the operationResult parameter.
Example
Return a success and update last_password_reset attribute
If the change password operation succeeded, return thecallback function, and pass a null value as the error parameter and an object value as the profile parameter. If last_password_reset attribute is provided in the object, it will be updated on the user’s profile.
Example
Return a failure
If the change password operation failed, return thecallback function, and pass a null value as the error parameter and a false value as the operationResult parameter.
Example
Return an error
If an error occurs, returncallback function, and pass relevant error information as the error parameter.
Example
Language-specific script examples
Auth0 provides sample scripts for use with the following languages/technologies:- JavaScript
- ASP.NET Membership Provider (MVC3 - Universal Providers)
- ASP.NET Membership Provider (MVC4 - Simple Membership)
- MongoDB
- MySQL
- PostgreSQL
- SQL Server
- Windows Azure SQL Database