keys-to-password
v1.2.4
Published
Generate and recover passwords from private and public keys.
Downloads
37
Maintainers
Readme
keys-to-password
Generate and recover passwords via private and public keys.
Features
- Use of the private and public key concept to secure password recovery only by the private key owner.
- Generate passwords with unlimited length.
- Randomly generate passwords.
- Password can be modified easily in advance (see examples below).
- Option for using patterns (see more details below).
Browser Support
| | | | | --- | --- | --- | --- | --- | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ |
Installation
npm i keys-to-password
yarn add keys-to-password
import
CommonJS
const { Password } = require("keys-to-password");
ES6
import { Password } from "keys-to-password";
Default usage
const password = new Password("your-private-key");
password.setKeyboard(); // Password can contain all keyboard characters
password.generate(); // Default password-length = 12
password.getPassword(); // => '?gj39?GdA_gkf'
const publicKey = password.getPublicKey(); // save into user storage
const passwordRecover = new Password("your-private-key", publicKey);
passwordRecover.setKeyboard();
passwordRecover.generate();
passwordRecover.getPassword(); // => '?gj39?GdA_gkf'
Visual Demonstration Of The Package Concept
Generic example
1) Generate password
const password = new Password("your-private-key");
password.setKeyboard();
password.generate({ passLength: 20 });
password.getPassword(); // => 'QS'-Z+8Z,:^1c%56`6h7'
2) Get password's public-key from the generated password
const publicKey = password.getPublicKey();
3) Recover password by the private and public keys
const passwordRecover = new Password("your-private-key", publicKey);
passwordRecover.setKeyboard();
passwordRecover.generate({ passLength: 20 });
4) Retrieve the password
passwordRecover.getPassword(); // => 'QS'-Z+8Z,:^1c%56`6h7'
Modify password using arguments
1) Modify keyboard
const password = new Password('your-private-key');
// The keyboard holds the characters from which you can generate passwords
const keyboardConfig = {
avoidChars: "1a$", // Characters 1,a,$ will not be in the generated password
isContainDigits: true,
isContainUpperCase: false, // Uppercase letters will not be in the generated password
isContainLowerCase: true,
isContainSymbols: true,
mustContainChars: "d3", // Assign d,3 characters to the keyboard
}
password.setKeyboard(keyboardConfig);
2) Extra generation options
const generateConfig = {
passLength: 20,
passStartsWith: "abc", // Generated password will start with the string 'abc'
passEndsWidth: "xyz" // Generated password will end with the string 'abc'
}
password.generate(generateConfig);
3) Retrieve the password
password.getPassword(); // => 'abc3s:#dfs$2kl~d3xyz'
4) To recover your password keep your config objects as well as your public-key stored
const publicKey = password.getPublicKey();
5) Recover the password
const passwordRecover = new Password("your-private-key", publicKey);
passwordRecover.setKeyboard(keyboardConfig);
passwordRecover.generate(generateConfig);
passwordRecover.getPassword(); // => 'abc3s:#dfs$2kl~d3xyz'
Modify password using pattern function only
const password = new Password("your-private-key");
password.generateFromPattern("A_\\d{10}-PASS");
password.getPassword(); // => 'A_2563495820-PASS'
- To recover your password keep your pattern string as well as your public-key stored.
Pattern's syntax options:
- All keyboard characters.
- \d{n} => assign n digits.
- \u{n} => assign n uppercase letters.
- \l{n} => assign n lowercase letters.
- \s{n} => assign n symbol characters.