Skip to content

tanmoypaul1005/password-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

genie-password-validator

A password validation library for JavaScript

Installation

npm install genie-password-validator

Usage

To use the `genie-password-validator` package in your project, follow these steps:

  1. Import the package into your code:
    const { isStrongPassword } = require("genie-password-validator");
  2. Define the password to be checked and an optional configuration object:
    const password = "YourPassword123!";
    const options = {
        minUppercase: 1,
        minLowercase: 1,
        minDigits: 1,
        minSpecialChars: 1,
        minLength: 8,
    };
  3. Call the `isStrongPassword` function and pass in the password and options:
    const result = isStrongPassword(password, options);
  4. You can then use the `result` object to handle the validation outcome in your code.
    if (result.isValid) {
        console.log("Password is strong and meets all criteria.");
    } else {
        console.log("Password validation failed. Reasons:");
        result.messages.forEach message => {
            console.log(message);
        });
    }

Using genie-password-validator in a React.js Project

If you're working on a React.js project and need to implement password validation, you can use the `genie-password-validator` package as follows:

  1. Install the package in your React project using npm:
  2. npm install genie-password-validator
  3. Import the `isStrongPassword` function in your React component where you need password validation.
  4. 
    import { isStrongPassword } from 'genie-password-validator';
                
  5. Use the function to validate passwords in your React component, such as during user registration or password change processes. Here's a simple example:
  6. 
    const password = "YourPassword123!";
    const options = {
        minUppercase: 1,
        minLowercase: 1,
        minDigits: 1,
        minSpecialChars: 1,
        minLength: 8,
    };
    

    const result = isStrongPassword(password, options);

    if (result.isValid) { console.log("Password is strong and meets all criteria."); } else { console.log("Password validation failed. Reasons:"); result.messages.forEach(message => { console.log(message); }); }

Configuration Options

You can configure the password validation by specifying the following options in the options object:

  • minUppercase: Minimum number of uppercase letters.
  • minLowercase: Minimum number of lowercase letters.
  • minDigits: Minimum number of digits.
  • minSpecialChars: Minimum number of special characters (e.g., !@#$%^&*()_+{}[]:;<>,.?~/-).
  • minLength: Minimum password length.

License

This package is licensed under the MIT License. Feel free to use and contribute to it.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published