README
PW-Simplified
Whats new in Version 1.1.2?
- Added support for ES-Syntax (import/export)
- Fixed some Bugs
Note: In later versions this module will completely switch to be an ES-module!
A small module for generating, validating and rating passwords based on changeable configurations
How to get started?
- First of All you will need to install the module with:
npm i pw-simplified
- Then you will need to require the module into your file with for example:
1) Using CommonJS:
const PW = require('pw-simplified'); // returns Class
const Pw = new PW(object1,object2,object3); // creating new Instance
2) Using ES-Module:
import PW from "pw-simplified"; // importing the Class
const Pw = new PW(object1,object2,object3); // creating new Instance
- in order to use ES-Modules just add to your package.json:
{
...,
"type": "module",
...
}
Note: The module will return a Class with all the necessary methods!
What arguments are needed for the Constructor?
The Constructor accepts
3
Objects, which are used to configurate the module to your needs.The first object configurates the Generating of Passwords
The second object configurates the Validating of Passwords
The third object configurates the Rating of Passwords
What properties do these configuration objects have?
First
object - for Generating Passwords- Explained with an example:
const configurationOfGenerating = { lowercase : true, // if false -> no lowercase characters in the generated Password uppercase : true, // if false -> no uppercase characters in the generated Password numbers : true, // if false -> no numbers in the generated Password special : `!"#$%&'()*+,-./:;<=>?@[]^_{|}~`, // if false -> no special characters in the generated Password length : 12 // if false -> Error } // All these properties have default values if not set: { lowercase : false, uppercase : false, numbers : false, special : `!"#$%&'()*+,-./:;<=>?@[]^_{|}~`, length : 8 }
Second
object - for Validating Passwords- Explained with an example:
const configurationOfValidating = { lowercaseRequired : true, // if false -> no lowercase character check in the Password uppercaseRequired : true, // if false -> no uppercase characters check in the Password numbersRequired : true, // if false -> no numbers check in the Password specialRequired : `!"#$%&'()*+,-./:;<=>?@[]^_{|}~`, // if false -> no special characters check in the Password minLength : 8, // if false or true -> Error maxLength : 30 // if false or true -> Error } // All these properties have default values if not set: { lowercaseRequired : false, uppercaseRequired : false, numbersRequired : false, specialRequired : `!"#$%&'()*+,-./:;<=>?@[]^_{|}~`, minLength : 8, maxLength : 30 }
Third
object - for Rating Passwords- Explained with an example:
const configurationOfRating = { lowercaseCheck : true, // if false -> no lowercase character check in the Password uppercaseCheck : true, // if false -> no uppercase characters check in the Password numbersCheck : true, // if false -> no numbers check in the Password specialCheck : `!"#$%&'()*+,-./:;<=>?@[]^_{|}~`, // if false -> no special characters check in the Password minLengthCheck : 8, // if false or true -> Error maxLengthCheck : 30, // if false or true -> Error output : 'numeric' // two options 'string' or 'numeric' } // All these properties have default values if not set: { lowercaseCheck : false, uppercaseCheck : false, numbersCheck : false, specialCheck : `!"#$%&'()*+,-./:;<=>?@[]^_{|}~`, minLengthCheck : 8, maxLengthCheck : 30, output: 'string' }
Note: Not pre-defined properties will be ignored
How to call the methods?
After you created a new Instance you have 4 methods to choose:
generatePW()
- no arguments needed when calling - return generated Password
const pw = Pw.generatePW(); // example return with the example configuration from above: `e05-_RF]>72#`
validatePW(pw)
- argument is the pw to be checked as a string - returns boolean
const valid = Pw.validatePW(pw); // example return with the example configuration from above: true
ratePW(pw)
- argument is the pw to be rated as a string or number - returns rating as string or number
const rating = Pw.ratePW(pw); // example return with the example configuration from above: 'medium'
ratePWGeneral(pw)
- argument is the pw to be rated as a string - returns rating as string or number- This method rates the Password on a more General level - so its not configurable
- It will check if the Password is at least 8 characters long, has uppercase, lowercase, number and special. Depending on result it returns from
very weak
tovery strong
or from 1 to 5.
const ratingGeneral = Pw.ratePWGeneral(pw); // example return with the example configuration from above: 'very strong'