Skip to main content
The Change Password script implements the defined function to change the specified user’s password in the external database. We recommend naming this function 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

The changePassword function should:
  • Update the user’s password in the external database.
  • Return true (or an object containing the last_password_reset property) if the password change operation succeeded. If the last_password_reset property is present in the object, it will be updated on the user’s profile.
  • Return false if the password change operation failed.
  • Return an error if the external database could not be reached.

Definition

The changePassword function accepts three parameters and returns a callback function:
ParameterTypeDescription
emailStringUser’s email address in Auth0 and external database.
newPasswordStringValue 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.
callbackFunctionUsed to pass data or operation result data through the pipeline.

Example

This is a pseudo-JavaScript example of how you could implement the changePassword function. For language-specific examples, read Language-specific script examples.

Encryption

Avoid logging, storing, or transporting the password credential anywhere in its unencrypted form.
To prevent any potential data leak, encrypt the password value using a cryptographic hash encryption library such as bcrypt.

Example

Callback function

The callback function accepts two parameters and is used to pass error data or indicate the result of the operation.

Definition

ParameterTypeRequiredDescription
errorObjectRequiredContains error data.
operationResultBooleanOptionalIndicates the result of the change password operation.
resultObjObjectOptionalIndicates 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 the callback 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 the callback 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 the callback 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, return callback 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

Learn more