1.2.0 • Published 2 years ago

@codexcentral/check-format-password v1.2.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

check-format-password

Allow checking password format

Installation

npm install @codexcentral/check-format-password

Usage

1. Import the function

import {
  checkFormatPassword,
  TConfig,
} from "@codexcentral/check-format-password";

2. Call the function

Example 1

const config: TConfig = {
  length: {
    min: {
      value: 2,
      message: "Password is too short.",
    },
    max: {
      value: 20,
      message: "Password is too long.",
    },
  }
};
const password = "Password123@";
const result = checkFormatPassword(password, config);

console.log(result);
// {
//   isValid: true,
//   message: "Password is valid."
// }

Example 2

const config = {
  number: {
    allow: true,
    message: "Password must contain at least one number.",
  },
};
const passwordCheck = "Password@";
const result = checkFormatPassword(passwordCheck, config);

console.log(result);
/*
 {
  isValid: false,
  message: [
       'Password must contain at least one number.',
       'Password must contain at least one special character.'
     ]
 }
*/

Attributes of "TConfig"

AttributeTypeRequiredDefault
lengthobjectfalse{ min: { value: 8, message: "Password is too short." }, max: { value: 20, message: "Password is too long." } }
length.minobjectfalse{ value: 8, message: "Password is too short." }
length.min.valuenumberfalse8
length.min.messagestringfalse"Password is too short."
length.maxobjectfalse{ value: 64, message: "Password is too long." }
length.max.valuenumberfalse64
length.max.messagestringfalse"Password is too long."
stringobjectfalse{ allow: true, message: "Password must contain at least one letter." }
string.allowbooleanfalsetrue
string.messagestringfalse"Password must contain at least one letter."
string.upperCaseobjectfalse{ allow: true, message: "Password must contain at least one uppercase letter." }
string.upperCase.allowbooleanfalsetrue
string.upperCase.messagestringfalse"Password must contain at least one uppercase letter."
string.lowerCaseobjectfalse{ allow: true, message: "Password must contain at least one lowercase letter." }
string.lowerCase.allowbooleanfalsetrue
string.lowerCase.messagestringfalse"Password must contain at least one lowercase letter."
numberobjectfalse{ allow: true, message: "Password must contain at least one number." }
number.allowbooleanfalsetrue
number.messagestringfalse"Password must contain at least one number."
specialCharobjectfalse{ allow: true, message: "Password must contain at least one special character." }
specialChar.allowbooleanfalsetrue
specialChar.messagestringfalse"Password must contain at least one special character."

Credits

These code was written by Roberto Silva Z.

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago