stroganoff
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

Are your users' passwords stroganoff?

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

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

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

Option Default Description Optional
numbers 1 Minimum amount of numbers the password should include true
upper 1 Minimum amount of uppercase characters the password should include true
minLen 12 Minimum password length true
maxLen 64 Maximum password length true
special 1 Minimum amount of special characters the password should include true
validMessage 'Your password is stroganoff' The message to return for a valid password true
invalidMessage 'Beef Leek stew' The message to return for an invalid password true
specific true Show the specific fields that are invalid true

Dependents (0)

Package Sidebar

Install

npm i stroganoff

Weekly Downloads

64

Version

1.2.2

License

MIT

Unpacked Size

42.6 kB

Total Files

14

Last publish

Collaborators

  • localzadmin