Code Monkey home page Code Monkey logo

stroganoff's Introduction

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

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

stroganoff's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar evert avatar harsilspatel avatar tomanagle avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

evert erdal-pb

stroganoff's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): Replace dependency rollup-plugin-node-resolve with @rollup/plugin-node-resolve 6.0.0
  • chore(deps): Update NPM (jest, lint-staged, rollup, rollup-plugin-typescript2, semantic-release, ts-jest, typedoc, typescript)
  • chore(deps): Update Buildkite plugins (docker, docker-login)
  • chore(deps): Update buildkite plugin docker to v5
  • chore(deps): Update dependency lint-staged to v13
  • chore(deps): Update dependency rimraf to v5
  • chore(deps): Update dependency rollup to v3
  • chore(deps): Update dependency semantic-release to v21
  • chore(deps): Update dependency typescript to v5
  • chore(deps): Update dependency uuid to v9 (uuid, @types/uuid)
  • chore(deps): Update jest monorepo to v29 (major) (jest, ts-jest)

Detected dependencies

buildkite
.buildkite/pipeline.yml
  • docker-login v2.0.1
  • docker v3.5.0
  • docker-login v2.0.1
  • docker v3.5.0
npm
package.json
  • lint-staged ^10.3.0
  • lodash.camelcase 4.3.0
  • rimraf 3.0.2
  • rollup 2.32.1
  • rollup-plugin-commonjs 10.1.0
  • rollup-plugin-json ^4.0.0
  • rollup-plugin-node-resolve 5.2.0
  • rollup-plugin-sourcemaps 0.6.3
  • rollup-plugin-typescript2 0.28.0
  • semantic-release ^17.1.1
  • typedoc ^0.19.1
  • typescript 4.0.5
  • @types/uuid ^8.3.4
  • jest 26.6.0
  • ts-jest 26.4.3
  • uuid ^8.3.2
  • node >=6.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>localz/renovate-config)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.