Email Armor
Password Management

Reset Password

Integrate the reset password feature to allow users to securely reset their password if forgotten.

Reset Password Feature

The Forgot Password feature allows users to securely reset their password if they’ve forgotten it. By integrating this feature, you provide a user-friendly and secure way for users to regain access to their accounts.

Step 1: Sending OTP for Verification (POST Request)

Overview

In this step, an OTP (One-Time Password) is generated and sent to the user's registered email address to verify their identity during the password reset process.

1. Integration Example

import { forgotPassword } from "email-armor";
 
let response = { message: "", status: 0 };
 
// Handle forgot password based on whether it's an email or username
if (userNameOrEmail.includes('@')) {
    const forgotPasswordResponse = await forgotPassword(userNameOrEmail, '', userAgent, userIP);
    response = { message: forgotPasswordResponse.message || "", status: forgotPasswordResponse.status };
} else {
    const forgotPasswordResponse = await forgotPassword('', userNameOrEmail, userAgent, userIP);
    response = { message: forgotPasswordResponse.message || "", status: forgotPasswordResponse.status };
}

2. Error Responses

Status CodeMessage
400Either userName or userEmail must be provided!
400Invalid userName!
400Invalid Email!
400Please Validate Your Details.
401Your device is unauthorized.
429OTP request limit exceeded. Please try again later.
500An unexpected error occurred. Please report this issue at GitHub.

3. Success Response

A 201 response indicates that the OTP has been successfully sent to the user's email. The response will include:

{ 
    message: "OTP sent to mail!", 
    status: 201 
}

Step 2: Verifying OTP and Updating the Password (PUT Request)

Once the OTP has been sent and received, this step verifies the OTP and allows the user to update their password.

1. Integration

import { forgotPassword } from "email-armor";
let response = { message: "", status: 0 };
// Handle password update based on whether it's an email or username
if (userNameOrEmail.includes('@')) {
    const signInResponse = await updatePassword(userNameOrEmail, '', userAgent, otp, newPassword);
    response = { message: signInResponse.message || "", status: signInResponse.status };
} else {
    const signInResponse = await updatePassword('', userNameOrEmail, userAgent, otp, newPassword);
    response = { message: signInResponse.message || "", status: signInResponse.status };
}

2. Error Responses

Status CodeMessage
400Either userName or userEmail must be provided!
400OTP is required!
400New password is required!
400Invalid userName!
400Invalid Email!
400Please Validate Your Details.
400OTP is expired!
400Invalid OTP!
401Your device is unauthorized.
500An unexpected error occurred. Please report this issue at GitHub.

3. Success Response

A 201 response indicates the password has been successfully updated. The response will include:

{ 
    message: "Password updated successfully!", 
    status: 201 
}

Note: After successfully updating the password, redirect the user to the login page so they can authenticate with their new credentials.

On this page