Socket
Socket
Sign inDemoInstall

generate-password

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.1 to 1.6.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# 1.6.0 / 2021-1-14
Add specifying a list of symbols to substitute defaults.
#### Notable Changes
- [`f0db9f29d`](https://github.com/brendanashworth/generate-password/commit/f0db9f29d932162a6cb2d24e98297d987c1ae6d9) - respect list of symbols (Dillon Streator)
- [`c1946ea44`](https://github.com/brendanashworth/generate-password/commit/c1946ea444cb632d9b507615312dfa08ef908902) - feat: Add jsdoc to ts types and export Options interface (Eddie CooRo)
# 1.5.1 / 2020-2-10

@@ -2,0 +9,0 @@ Add lowercase option to TypeScript file.

@@ -13,2 +13,11 @@ /*eslint no-unused-vars: "off"*/

// Generate one password with provided list of symbols.
password = generator.generate({
length: 15, // defaults to 10
numbers: true, // defaults to false
symbols: '!@#$%&*', // defaults to false
uppercase: true, // defaults to true
strict: true // defaults to false
});
// Generate ten bulk.

@@ -15,0 +24,0 @@ var passwords = generator.generateMultiple(10, {

5

package.json
{
"name": "generate-password",
"version": "1.5.1",
"version": "1.6.0",
"description": "Easy library for generating unique passwords.",

@@ -28,3 +28,2 @@ "main": "main.js",

"homepage": "https://github.com/brendanashworth/generate-password",
"dependencies": {},
"devDependencies": {

@@ -34,3 +33,3 @@ "chai": "^1.10.0",

"eslint": "^6.5.1",
"jscover": "^1.0.0",
"jscover": "^0.1.1",
"mocha": "^7.0.0",

@@ -37,0 +36,0 @@ "mocha-lcov-reporter": "^1.2.0",

20

README.md

@@ -50,13 +50,13 @@ # Generate Password [![Build Status](https://travis-ci.org/brendanashworth/generate-password.svg?branch=master)](https://travis-ci.org/brendanashworth/generate-password) [![codecov](https://codecov.io/gh/brendanashworth/generate-password/branch/master/graph/badge.svg)](https://codecov.io/gh/brendanashworth/generate-password)

| Name | Description | Default Value |
|--------------------------|-----------------------------------------------------|---------------|
| length | Integer, length of password. | 10 |
| numbers* | Boolean, put numbers in password. | false |
| symbols* | Boolean, put symbols in password. | false |
| lowercase* | Boolean, put lowercase in password | true |
| uppercase* | Boolean, use uppercase letters in password. | true |
| excludeSimilarCharacters | Boolean, exclude similar chars, like 'i' and 'l'. | false |
| exclude | String, characters to be excluded from password. | '' |
| strict | Boolean, password must include at least one character from each pool. | false |
| Name | Description | Default Value |
|--------------------------|-----------------------------------------------------------------------|---------------|
| length | Integer, length of password. | 10 |
| numbers* | Boolean, put numbers in password. | false |
| symbols* | Boolean or String, put symbols in password. | false |
| lowercase* | Boolean, put lowercase in password | true |
| uppercase* | Boolean, use uppercase letters in password. | true |
| excludeSimilarCharacters | Boolean, exclude similar chars, like 'i' and 'l'. | false |
| exclude | String, characters to be excluded from password. | '' |
| strict | Boolean, password must include at least one character from each pool. | false |
*At least one should be true.

@@ -1,12 +0,51 @@

interface Options {
length?: number
numbers?: boolean
symbols?: boolean
lowercase?: boolean
uppercase?: boolean
excludeSimilarCharacters?: boolean
exclude?: string
strict?: boolean
export interface GenerateOptions {
/**
* Length of the generated password.
* @default 10
*/
length?: number;
/**
* Should the password include numbers
* @default false
*/
numbers?: boolean;
/**
* Should the password include symbols
* @default false
*/
symbols?: boolean;
/**
* Should the password include lowercase characters
* @default true
*/
lowercase?: boolean;
/**
* Should the password include uppercase characters
* @default true
*/
uppercase?: boolean;
/**
* Should exclude visually similar characters like 'i' and 'I'
* @default false
*/
excludeSimilarCharacters?: boolean;
/**
* List of characters to be excluded from the password
* @default ""
*/
exclude?: string;
/**
* Password should include at least one character from each pool
* @default false
*/
strict?: boolean;
}
export function generate (options?: Options): string
export function generateMultiple (amount: number, options?: Options): string[]
/**
* Generate one password with the given options.
*/
export function generate(options?: GenerateOptions): string;
/**
* Bulk generate multiple passwords at once, with the same options for all.
*/
export function generateMultiple(count: number, options?: GenerateOptions): string[];

@@ -60,2 +60,9 @@ var crypto = require('crypto');

// Treat symbol differently if explicit string is provided
if (rule.name === 'symbols' && typeof options[rule.name] === 'string') {
// Create a regular expression from the provided symbols
var re = new RegExp('['+options[rule.name]+']');
return re.test(password);
}
// Run the regex on the password and return whether

@@ -111,3 +118,7 @@ // or not it matches.

if (options.symbols) {
pool += symbols;
if (typeof options.symbols === 'string') {
pool += options.symbols;
} else {
pool += symbols;
}
}

@@ -114,0 +125,0 @@

@@ -111,2 +111,12 @@ var assert = require('chai').assert,

it('should respect explicit list of symbols when provided', function() {
var passwords = generator.generateMultiple(amountToGenerate, { length: 10, strict: true, symbols: '!', lowercase: true });
passwords.forEach(function (password) {
assert.notMatch(password, /[@#$%^&*()+_\-=}{[\]|:;"/?.><,`~]/, 'password does not have default symbols');
assert.match(password, /[!]/, 'password has provided symbol');
});
assert.equal(passwords.length, amountToGenerate);
});
it('should throw an error if rules don\'t correlate with length', function() {

@@ -113,0 +123,0 @@ assert.throws(function() {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc