npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-multiple-password-validator

v2021.10.28-1.1.5

Published

A React Component to display the success or failure of multiple password strength rules

Downloads

11

Readme

React Multiple Password Validator

npm version Minzipped Size NPM Downloads NPM License Issues Pull Requests Twitter

A React Component to display the success or failure of password strength rules that updates as a user types.

Example

React Password Checklist Demo

Install in your project

npm install --save react-multiple-password-validator

yarn add react-multiple-password-validator

Note: react is a peer dependency. You should be using this in a React project.

Example Usage

import React, {useState} from "react"
import PasswordChecklist from "react-multiple-password-validator"

const SignUp = () => {
	const [password, setPassword] = useState("")
	const [passwordAgain, setPasswordAgain] = useState("")
	return (
		<form>
			<label>Password:</label>
			<input type="password" onChange={e => setPassword(e.target.value)}>
			<label>Password Again:</label>
			<input type="password" onChange={e => setPasswordAgain(e.target.value)}>

			<PasswordChecklist
				rules={["minLength","specialChar","number","capital","match"]}
				minLength={5}
                specialCharLength={2}
                numberLength={2}
                capitalLength={2}
                lowerCaseLength={2}
				value={password}
				valueAgain={passwordAgain}
				onChange={(isValid) => {}}
			/>
		</form>
	)
}

Custom Messages/Translations

import React, {useState} from "react"
import PasswordChecklist from "react-multiple-password-validator"

const SignUp = () => {
	const [password, setPassword] = useState("")
	const [passwordAgain, setPasswordAgain] = useState("")
	return (
		<form>
			<label>Password:</label>
			<input type="password" onChange={e => setPassword(e.target.value)}>
			<label>Password Again:</label>
			<input type="password" onChange={e => setPasswordAgain(e.target.value)}>

			<PasswordChecklist
				rules={["minLength","specialChar","number","capital","match"]}
				minLength={8}
				value={password}
				valueAgain={passwordAgain}
                specialCharLength={2}
                numberLength={2}
                capitalLength={2}
                lowerCaseLength={2}
				messages={{
					minLength: `Password has ${minLength} minimum length.`,
                    specialChar: `Password has ${specialCharLength} special characters.`,
                    lowercase: `Password has ${lowerCaseLength} lowercase letters.`,
                    number: `Password has ${numberLength} numbers.`,
                    capital: `Password has ${capitalLength} capital letters.`,
                    match: `Passwords match.`,
				}}
			/>
		</form>
	)
}

Available Rules

Customize the component to display only the rules you need in the desired order you wish to display them.

minLength

Valid if the password meets the minimum length. Requires minLength prop to be included.

maxLength

Valid if the password meets the maximum length. Requires maxLength prop to be included.

specialChar

Valid if the password contains a special character from this list.

number

Valid if the password contains a number.

capital

Valid if the password contains a capital letter.

match

Valid if the password matches the confirm password valid. Requires valueAgain prop to be included.

lowercase

Valid if the password contains a lowercase letter

notEmpty

Valid if the password and confirm passwords both contain any character. Requires valueAgain prop to be included.

Props

| Prop | Description | Type | Required | Default | | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------- | ----------------- | | rules | Rules to display in the order desired.Options are minLength, maxLength, specialChar,number, capital, match, lowercase, notEmpty | array | yes | | value | Current potential password | string | yes | | valueAgain | Current potential password confirmation | string | Only withmatch rule | | minLength | Minimum Password Length | number | Only withminLength rule | | maxLength | Maximum Password Length | number | Only withmaxLength rule | | specialCharLength | Maximum Special Characters Length | number | Only withspecialCharLength rule | | numberLength | Maximum Number Length | number | Only withnumberLength rule | | capitalLength | Maximum Capital Length | number | Only withcapitalLength rule | | lowerCaseLength | Maximum Lower Case Length | number | Only withlowerCaseLength rule | | onChange | Callback that is triggered when thepassword becomes valid or invalid acrossall rules. | function | | (isValid) => {} | | messages | Object with keys as rules, and values as strings to use as the message to be displayed | object | | | className | Class applied to the entire component | string | | | rtl | apply rtl styles | boolean | | false | | style | Inline styles applied to theouter component wrapper | object | | | iconSize | Size of ✔ or 𐄂 icon | number | | 18 | | validColor | Color of checkmark icon. Not used with custom iconComponents | string | | #4BCA81 | | invalidColor | Color of X icon. Not used with custom iconComponents | string | | #FF0033 | | iconComponents | Optional object containing keys of ValidIcon and InvalidIcon with a React Node to be displayed in place of icon. Both icons required if used. Example: {ValidIcon: <img src="valid.png" />, InvalidIcon: <img src="invalid.png" />} | object | | |

Available Classes

  • .valid - Valid Message
  • .invalid - Invalid Message

Run Locally

npm run storybook

yarn storybook