1.2.2 • Published 9 months ago

stroganoff v1.2.2

Weekly downloads
72
License
MIT
Repository
-
Last release
9 months ago

Are your users' passwords stroganoff?

Don't let your users be Russian their passwords, make sure they're stroganoff.

  • Validate passwords server-side
  • Validate passwords client-side
  • Validate passwords as the user types
  • Validate passwords on submit

npm.io

Install the package:

yarn add stroganoff

Setup

Create your own password validator with custom options:

import Stroganoff, { StroganoffOptions } from 'stroganoff';

   const options: StroganoffOptions = {
      /*
       * Minimum amount of numbers the password should include
       * Default: 1
       * Optional
       */
      numbers: 1,

      /*
       * Minimum amount of uppercase characters the password should include
       * Default: 1
       * Optional
       */
      upper: 1,

      /*
       * Minimum amount of special characters the password should include
       * Default: 1
       * Optional
       */
      special: 1,

      /*
       * Minimum password length
       * Default: 12
       * Optional
       */
      minLen: 12,

      /*
       * Maximum password length
       * Default: 64
       * Optional
       */
      maxLen: 64,

      /*
       * Show the specific fields that are invalid
       * Default: true
       * Optional
       */
      specific: true,

      /*
       * The message to return for a valid password
       * Default: 'Your password is stroganoff'
       * Optional
       */
      validMessage: 'Your password is stroganoff',

      /*
       * The message to return for an invalid password
       * Default: 'Beef stew'
       * Optional
       */
      invalidMessage: 'Beef stew'
    }

const passwordValidator = new Stroganoff(options);

export default passwordValidator

Validating passwords:

const myPassword = '123abc';

/* 
{
  "valid": false,
  "message": "Beef Leek stew",
  "specific": {
    "numbers": true,
    "upper": false,
    "special": false,
    "minLen": false,
    "maxLen": true
  }
}
*/
const result = passwordValidator.validate(myPassword)

With Joi

Stroganoff exposes a regex expression that matches your password strength requirements. You can use the expression in your Joi validation.

const schema = {
 name: Joi.string().required(),
 password: Joi.string().pattern(validatePassword.expression)
}

With Yup

const schema = yup.object({
  name: yup.string().required('Name is required'),
  password: yup
    .string()
    .required('Password is a required field')
    .matches(passwordValidator.expression, 'Password is not strong enough')
})

Options

OptionDefaultDescriptionOptional
numbers1Minimum amount of numbers the password should includetrue
upper1Minimum amount of uppercase characters the password should includetrue
minLen12Minimum password lengthtrue
maxLen64Maximum password lengthtrue
special1Minimum amount of special characters the password should includetrue
validMessage'Your password is stroganoff'The message to return for a valid passwordtrue
invalidMessage'Beef Leek stew'The message to return for an invalid passwordtrue
specifictrueShow the specific fields that are invalidtrue