0.0.5 • Published 3 years ago

react-native-password-strength-meter v0.0.5

Weekly downloads
927
License
MIT
Repository
github
Last release
3 years ago

react-native-password-strength-meter npm version npm downloads

A highly customisable password strength meter implementation with minimal dependencies.

Show Cases

Type Bar

IOSAndroid
BarBar

Type Box

IOSAndroid
BoxBox

Type Circle

IOS
Circle

Type Text

IOSAndroid
TextText

Getting Started

Installation

$ npm i react-native-password-strength-meter --save

Basic Usage

Password Input Usage

import React, { Component } from 'react';
import {
  View,
  StyleSheet,
  TextInput
} from 'react-native';

import RNPasswordStrengthMeter from 'react-native-password-strength-meter';

export default class PasswordInput extends Component {
  onChange = (password, score, { label, labelColor, activeBarColor }) => {
    console.log(password, score, { label, labelColor, activeBarColor });
  }
  render() {
    return (
      <View style={styles.container}>
        <RNPasswordStrengthMeter
          onChangeText={this.onChange}
          meterType="bar"
        />
      </View>
    );
  }
}

Component Usage

import React, { Component } from 'react';
import {
  View,
  StyleSheet,
  TextInput
} from 'react-native';

import { BarPasswordStrengthDisplay } from 'react-native-password-strength-meter';

export default class BarComponent extends Component {
  state = {
    password: '',
  }

  onChange = password => this.setState({ password })

  render() {
    const { password } = this.state;
    return (
      <View style={styles.container}>
        <TextInput style={styles.textInput} onChangeText={this.onChange} />
        <BarPasswordStrengthDisplay
          password={password}
        />
      </View>
    );
  }
}

Properties

Password Input Props

PropDefaultTypeDescription
onChangeTextrequiredfuncCallback to Return Input text changes (password, score, { label, labelColor, activeBarColor }) => {}
defaultPassword""stringDefault Password Value
containerWrapperStyle{}objectContainer wrapper style
imageWrapperStyle{}objectEye Image wrapper style
imageStyle{}objectEye Image style
inputWrapperStyle{}objectText Input wrapper style
inputStyle{}objectText Input style
placeholderStyle{}objectText Input placeholder style
meterTypebarenumMeter Type. Can be bar, box, circle, text
inputPropsDefaultsobjectReact Native's TextInput Props
passwordPropsDefaultsobjectPassword Component Props

Bar Component Props

PropDefaultTypeDescription
passwordrequiredstringPassword Value
touched""boolField Touched
scoreLimit100numberPassword Score's maximum value
variationsDefaultsobjectDifferent validations in regex to calculate password score
minLength5numberMinimum length of the password to validate
labelVisibletrueboolLabel Visible
levelsDefaultsarrayDifferent Levels to calculate password score
wrapperStyle{}objectWrapper style
barContainerStyle{}objectBar Container style
barStyle{}objectBar style
labelStyle{}objectLabel style
barColor#f1f3f4stringBar background color
widthdeviceWidth - 20numberWidth of bar

Box Component Props

PropDefaultTypeDescription
passwordrequiredstringPassword Value
touched""boolField Touched
scoreLimit100numberPassword Score's maximum value
variationsDefaultsobjectDifferent validations in regex to calculate password score
minLength5numberMinimum length of the password to validate
labelVisibletrueboolLabel Visible
levelsDefaultsarrayDifferent Levels to calculate password score
wrapperStyle{}objectWrapper style
boxContainerStyle{}objectBox Container style
boxStyle{}objectBox style
labelStyle{}objectLabel style
boxColor#f1f3f4stringBox background color
widthdeviceWidth - 20numberWidth of box container which will be split based on the levels
boxSpacing2numberSpacing in between the boxes

Circular Component Props

PropDefaultTypeDescription
passwordrequiredstringPassword Value
labelVisibletrueboolLabel Visible
minLength5numberMinimum length of the password to validate
scoreLimit100numberPassword Score's maximum value
easeDuration500numberEase Duration of the meter needle
variationsDefaultsobjectDifferent validations in regex to calculate password score
levelsDefaultsarrayDifferent Levels to calculate password score
wrapperStyle{}objectWrapper style
outerCircleStyle{}objectOuter circle style
imageWrapperStyle{}objectImage wrapper style
imageStyle{}objectImage style
innerCircleStyle{}objectInner circle style
labelWrapperStyle{}objectLabel wrapper style
labelStyle{}objectLabel style
labelNoteStyle{}objectLabel note style
needleImageDefaultsstringAbsolute path to the needle image

Text Component Props

PropDefaultTypeDescription
passwordrequiredstringPassword Value
touched""boolField Touched
scoreLimit100numberPassword Score's maximum value
variationsDefaultsobjectDifferent validations in regex to calculate password score
minLength5numberMinimum length of the password to validate
labelVisibletrueboolLabel Visible
levelsDefaultsarrayDifferent Levels to calculate password score
wrapperStyle{}objectWrapper style
labelStyle{}objectLabel style

Defaults

defaultPassword: '',
containerWrapperStyle: {},
imageWrapperStyle: {},
imageStyle: {},
inputWrapperStyle: {},
inputStyle: {},
placeholderStyle: {},
meterType: 'bar',
   inputProps: {
    placeholder: 'Password',
  secureTextEntry: true,
},
passwordProps: {
   touched: false,
   scoreLimit: 100,
   variations: {
     digits: /\d/,
     lower: /[a-z]/,
     upper: /[A-Z]/,
     nonWords: /\W/,
   },
   minLength: 5,
   labelVisible: true,
   levels: [
     {
       label: 'Pathetically weak',
       labelColor: '#ff2900',
       activeBarColor: '#ff2900',
     },
     {
       label: 'Extremely weak',
       labelColor: '#ff3e00',
       activeBarColor: '#ff3e00',
     },
     {
       label: 'Very weak',
       labelColor: '#ff5400',
       activeBarColor: '#ff5400',
     },
     {
       label: 'Weak',
       labelColor: '#ff6900',
       activeBarColor: '#ff6900',
     },
     {
       label: 'So-so',
       labelColor: '#f4d744',
       activeBarColor: '#f4d744',
     },
     {
       label: 'Average',
       labelColor: '#f3d331',
       activeBarColor: '#f3d331',
     },
     {
       label: 'Fair',
       labelColor: '#f2cf1f',
       activeBarColor: '#f2cf1f',
     },
     {
       label: 'Strong',
       labelColor: '#14eb6e',
       activeBarColor: '#14eb6e',
     },
     {
       label: 'Very strong',
       labelColor: '#0af56d',
       activeBarColor: '#0af56d',
     },
     {
       label: 'Unbelievably strong',
       labelColor: '#00ff6b',
       activeBarColor: '#00ff6b',
     },
   ],
   wrapperStyle: {},
   labelStyle: {},
   width: deviceWidth - 20,
   
   // Bar
   barContainerStyle: {},
   barStyle: {},
   barColor: '#f1f3f4', 
   
   // Box
   boxContainerStyle: {},
   boxStyle: {},
   boxColor: '#f1f3f4',
   boxSpacing: 2,
   
   // Circle
   outerCircleStyle: {},
   imageWrapperStyle: {},
   imageStyle: {},
   innerCircleStyle: {},
   labelWrapperStyle: {},
   labelNoteStyle: {},
}

Password Score Algorithm

The Password Score calculator is based on this amazing Stackoverflow Post authored by @tm_lv.

Contribution

Questions

Feel free to contact me or create an issue