1.1.0 • Published 5 years ago

password-wizard v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Password Wizard

The Password Wizard is a simple password generator.


You can use it to help the user come up with a password when registering on your site. This package supports all types of modules. You can import it using Node.js modules, ES6 modules, or browser imports.

A simple example of use

For example, we import this package into the Node.js program. Also, we pass a length of 15 characters as a parameter. Then we call generate function to generate the password.

const PasswordWizard = require('password-wizard');

const passwordWizard = new PasswordWizard({
  length: 15,
});

console.log(passwordWizard.generate());

Run the program and get a password as a result

> node script.js

F3zKhov7P2V897d

If we hadn't passed the parameter, an 8-digit password would have been generated.

How to use this package?

First you need to install it (however, you can use it without installing via cdn). To install the package, run this command:

npm i password-wizard

Now you need to import it.

How to import?

There are 3 ways to import. Let's take a look at all of them.

Import directly to browser via cdn

First, we need to include a script with an attribute src equal to https://rawcdn.githack.com/vasilymens/password-wizard/b17cf5f1e38496511482b0d9fed721996e997684/build/script.js.

<script src="https://rawcdn.githack.com/vasilymens/password-wizard/b17cf5f1e38496511482b0d9fed721996e997684/build/script.js"></script>
<script>
  const passwordWizard = new PasswordWizard();

  console.log(passwordWizard.generate());
</script>

Now we can create an instance of the class PasswordWizard. Optionally, we can pass an object with parameters there. The list of possible parameters will be below.

After that, we call method generate and get a random password in the console.

Import using ES6 modules

It's very simple. Import the class, create an instance, call the method.

import PasswordWizard from 'password-wizard';

const passwordWizard = new PasswordWizard();

console.log(passwordWizard.generate());

Import using node modules

The whole process looks the same as with any other package.

const PasswordWizard = require('password-wizard');

const passwordWizard = new PasswordWizard({});

console.log(passwordWizard.generate());

What parameters can be passed?

As a parameter when instantiating the class, you can pass an object that will include 3 optional fields.

  1. Password length
  2. Types of characters required in a password
  3. Types of characters that can be in a password

Password length

This parameter is called length.

You must pass an integer as the length of the password. If you do not pass this parameter, an 8-digit password will be generated.

Types of characters required in a password

This parameter is called require.

You must pass an array of strings. The generated password is guaranteed to contain at least 1 character of each type. The list of character types is below.

This property is required to match the validation that some sites like to do — "your password must be at least 1 digit, at least 1 capital letter, and so on".

Types of characters that can be in a password

This parameter is called include.

You must pass an array of strings. The generated password can contain these types of characters.

What types of characters are there?

There are 5 types of characters.

  1. 'numbers' — 0123456789
  2. 'lowercase' — a-z
  3. 'uppercase' — A-Z
  4. 'symbols' — !@#\$%^&*-+=
  5. 'specialCharacters' — ~`"№;:(){}[]\|\'<>/?

What parameters are passed by default?

Here is an object with default parameters.

const options = {
  length: 8,
  require: ['numbers', 'lowercase', 'uppercase'],
  include: ['symbols'],
};

What else?

If the number of required character types exceeds the length of the password, an exception is thrown.

throw new Error('You require more character types than password length');
1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.0

5 years ago