0.2.0 • Published 2 years ago

pw-simplified v0.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

pw-simplified

Pw-Simplified making working with passwords easy


What is Pw-Simplified?

Pw-Simplified is a fast and small JavaScript / Typescript library. Its API is easy and intuitive and really shines with Typescript.


Core Features

  1. Password generation
  2. Password validation
  3. Password shuffling

Why Pw-Simplified?

It was created due to my own laziness and because I did not want to reapeat myself over and over again. So i thought about making a small module which is compact and leightweight.

Whats new in version 0.2.0 (shuffle)

Added

  • shuffle() - METHOD

Changed

  • README.md - Added Advanced Usage + New Version

A Brief Look

Installation

npm i pw-simplified

Import

Note: Default Imports a Class! Give it any name

// with require
const Pass = require('pw-simplified');

// with import
import Pass from 'pw-simplified';

Configuration

The constructor needs two objects for configuration.

  1. For generating passwords
  2. For validating passwords
const pw = new Pass({
    length: 8, // must set
    lowercase: true, // optional
    uppercase: true, // optional
    numbers: true, // optional
    special: true // optional also possible to add own "" with symbols - when true: ~`!@#$%^&*()_-+={[}]|\:;"'<,>.?/
}, {
    minLength: 8, // must set
    maxLength: 20, // optional
    lowercase: true, // optional
    uppercase: true, // optional
    numbers: true, // optional
    special: true // optional
});

Usage

// using the instance created in the configuration example above

// generating a new Password
const generatedPw = pw.generate(); // returns generated Password as a string
// example output: M2mZ!SdX

// validating a Password
if (pw.validate(generatedPw)) { // returns a boolean
    // if valid
} else {
    // if not valid
}
// output with M2mZ!SdX would be true

// shuffle a Password
const shuffledPw = pw.shuffle(generatedPw, 'Fisher Yates');
// output would be for example: mXdZM2S!

// if no second parameter is passed in, it will use 'Fisher Yates' as a standard value
// the option would be 'Sort', which uses the .sort() method

Advanced Usage

genConfig and valConfig

Using the setter of the genConfig / valConfig, gives you the possibility to partially change the config

// assuming that the instance is named pw
pw.genConfig = {numbers: true} // this will update the numbers prop and the rest will beunchanged
// so assuming the all props were false and length was 8, the new config would be
/*
  {
    length: 8,
    lowercase: false,
    uppercase: false,
    numbers: true,
    specials: false
  }
*/

// the setter of the valConfig also regenerates the valRegEx everytime it is set.

valRegEx

If you want to define your own RegEx for validating Passwords, just use the setter valRegEx.

// if you decided to change the current valRegEx, then you could that like:
pw.valRegEx = new RegExp(".+","g");
// this overwrites the current RegEx and replaces it. Now the validate method uses the RegEx.

// if you want to regenerate the modules RegEx simply use the valConfig setter and assign an empty object or an object with new values if wanted
pw.valConfig = {}
// this will trigger the method for generating the RegEx
0.1.0

2 years ago

0.1.2

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago