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-password-indicator

v1.0.0

Published

Package providing flexible yet powerful password input with fully customizable render

Downloads

903

Readme

npm version License: MIT Build Status Coverage Status

React Password Indicator

Package providing flexible yet powerful password input with fully customizable render.

Installation

You can install this package using one of these commands:

npm i --save react-password-indicator

yarn add react-password-indicator

This package also depends on react. Please make sure you have it installed as well.

Usage

Basic usage and demo

You can play with sandbox here:

Edit o772lmq6

Props

defaultValue

string | defaults to empty string

You can set the default input value via this prop.

minLen

number | defaults to 0

Predefined rule to check password minimal length. Uses >= operator, if you want to use > you have to use a custom rule.

maxLen

number | defaults to 0

Predefined rule to check password maximal length. Uses >= operator, if you want to use > you have to use a custom rule.

digits

number | defaults to 0

Predefined rule to check password for minimal number of digits. Uses >= operator, if you want to use > you have to use a custom rule.

specialChars

number | defaults to 0

Predefined rule to check password for minimal number of special characters (?!@#$%^&*)(+=._-}{,"'[]). Uses >= operator, if you want to use > or different special chars you have to use a custom rule.

uppercaseChars

number | defaults to 0

Predefined rule to check password for minimal number of uppercase characters. Uses >= operator, if you want to use > you have to use a custom rule.

mustMatch

string | defaults to undefined

Predefined rule to check if password matches given string. Can be used for password confirmation.

required

bool | defaults to false

Predefined rule to set password as required.

render

function({}) | required

You have to use this or the children to pass your custom render function. See more in [Render Prop Function](#Render Prop Function)

isVisible

boolean

Can be used in controlled mode to control the visibility of password in input element.

value

string

Can be used in controlled mode.

onChange

function()

This function is called when the input is changed and returns current input value.

onBlur

function()

This function is called when the input is blur event is fired and returns current input value.

onValidate

function()

This function is called when the value has been validated and returns the validation result.

validateOnBlur

boolean | defaults to false

If true, the value will be validated on input blur instead of input change.

defaultMessages

object

You can override default messages or add messages for your custom rules here. If you dont supply message for your custom rule here, then you have to provide the message in rule itself (see rules prop).

Should have following shape:

{
   // Override default message for predefined rule
  minLen: (val) => `Minimal password length is ${val}`,
  // If you dont need the value, string is also acceptable
  maxLen: 'Password is too long!',
  // Message for custom rule
  myRuleKey: 'Your custom message here',
}

rules

array

Array of additional custom rules in following format:

{
  key: 'myRuleKey', // required - each rule needs unique identification
  rule: (value, ruleValue) => value.indexOf(ruleValue) > -1, // required - the validation function (has to return true or false)
  // optional error message - required if you did not set the default message
  message: 'Password is not valid for my custom rule',
  value: '@' // allows dynamic rule value change  
}

If you don't need to change rule value dynamically, you can just skip it:

{
  key: 'myRuleKey', // required - each rule needs unique identification
  rule: (value) => value.indexOf('@') > -1, // required - the validation function (has to return true or false)
  // optional error message - required if you did not set the default message
  message: 'Password is not valid for my custom rule',  
}

Render Prop Function

This is where you render whatever you want to based on the state of react-password-indicator. You can either use the render prop:

<PasswordInput render={(props) => /* your render method implementation */} />

Or you can pass it as the children prop if you prefer to:

<PasswordInput>{(props) => /* your render method implementation */}</PasswordInput>

The properties of passed to this render method are listed below:

Render props passed to the render function

getInputProps

This method should be applied to the input you render.

getProgressProps

This method should be applied to the progress you render. It returns object of this shape:

{
  value: 2, // count of passed rules
  max: 7, // count of all rules
}

validate

This method returns all current errors or null when called. Useful for integration with informed.

toggleShowPassword

function

Function used to toggle password visibility.

hasRulePassed

function(key)

Returns true if password passed the validation on this rule.

valid

boolean

Indicates if the password has passed all the rules.

isVisible

boolean

Indicates if the password is visible (input element has type or 'text' instead of 'password').

errors

array

All the errors that occurred during password validation.

touched

boolean

Indicates if the password input has been changed.

rules

array

All the rules currently applied to password validation.

License

MIT