generate-pw 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -10
- package/dist/cli.min.js +7 -4
- package/dist/generate-pw.min.js +1 -1
- package/docs/README.md +329 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -19,10 +19,11 @@
|
|
|
19
19
|
### Randomly generate, strengthen, and validate cryptographically-secure passwords.
|
|
20
20
|
|
|
21
21
|
<a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
22
|
-
<a href="https://github.com/adamlui/js-utils/releases/tag/generate-pw-1.4.
|
|
22
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/generate-pw-1.4.4"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.4.4-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
23
23
|
<a href="https://www.npmjs.com/package/generate-pw?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/generate-pw?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
|
|
24
|
-
<a href="https://github.com/adamlui/js-utils/blob/generate-pw-1.4.
|
|
24
|
+
<a href="https://github.com/adamlui/js-utils/blob/generate-pw-1.4.4/generate-pw/dist/generate-pw.min.js"><img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/generate-pw/dist/generate-pw.min.js?branch=generate-pw-1.4.4&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
25
25
|
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:generate-pw/src/generate-pw.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Agenerate-pw%2Fsrc%2Fgenerate-pw.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
|
|
26
|
+
<a href="https://github.com/toolleeo/cli-apps#password-managers"><img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-c4a2bd?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
26
27
|
|
|
27
28
|
<br>
|
|
28
29
|
|
|
@@ -61,7 +62,7 @@ $ npm install generate-pw
|
|
|
61
62
|
|
|
62
63
|
### <img height=18 src="https://i.imgur.com/JIeAdsr.png"> Node.js
|
|
63
64
|
|
|
64
|
-
####
|
|
65
|
+
#### ECMAScript*:
|
|
65
66
|
|
|
66
67
|
```js
|
|
67
68
|
import * as pw from 'generate-pw';
|
|
@@ -80,14 +81,14 @@ const pw = require('generate-pw');
|
|
|
80
81
|
#### <> HTML script tag:
|
|
81
82
|
|
|
82
83
|
```html
|
|
83
|
-
<script src="https://cdn.jsdelivr.net/npm/generate-pw@1.4.
|
|
84
|
+
<script src="https://cdn.jsdelivr.net/npm/generate-pw@1.4.4/dist/generate-pw.min.js"></script>
|
|
84
85
|
```
|
|
85
86
|
|
|
86
87
|
#### ES6:
|
|
87
88
|
|
|
88
89
|
```js
|
|
89
90
|
(async () => {
|
|
90
|
-
await import('https://cdn.jsdelivr.net/npm/generate-pw@1.4.
|
|
91
|
+
await import('https://cdn.jsdelivr.net/npm/generate-pw@1.4.4/dist/generate-pw.min.js');
|
|
91
92
|
// Your code here...
|
|
92
93
|
})();
|
|
93
94
|
```
|
|
@@ -96,7 +97,7 @@ const pw = require('generate-pw');
|
|
|
96
97
|
|
|
97
98
|
```js
|
|
98
99
|
...
|
|
99
|
-
// @require https://cdn.jsdelivr.net/npm/generate-pw@1.4.
|
|
100
|
+
// @require https://cdn.jsdelivr.net/npm/generate-pw@1.4.4/dist/generate-pw.min.js
|
|
100
101
|
// ==/UserScript==
|
|
101
102
|
|
|
102
103
|
// Your code here...
|
|
@@ -104,7 +105,7 @@ const pw = require('generate-pw');
|
|
|
104
105
|
|
|
105
106
|
<br>
|
|
106
107
|
|
|
107
|
-
**💡 Note:** To always import the latest version (not recommended in production!) remove the `@1.4.
|
|
108
|
+
**💡 Note:** To always import the latest version (not recommended in production!) remove the `@1.4.4` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/generate-pw/dist/generate-pw.min.js`
|
|
108
109
|
|
|
109
110
|
<br>
|
|
110
111
|
|
|
@@ -287,7 +288,7 @@ Info commands:
|
|
|
287
288
|
|
|
288
289
|
## 🏛️ MIT License
|
|
289
290
|
|
|
290
|
-
**Copyright © 2024 [Adam Lui](https://github.com/adamlui) & contributors
|
|
291
|
+
**Copyright © 2024 [Adam Lui](https://github.com/adamlui) & contributors.**
|
|
291
292
|
|
|
292
293
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
293
294
|
|
|
@@ -310,7 +311,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
310
311
|
[CLI usage](https://github.com/adamlui/js-utils/tree/main/generate-ip#-command-line-usage) /
|
|
311
312
|
[Discuss](https://js-utils.com/discussions)
|
|
312
313
|
|
|
313
|
-
### <
|
|
314
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/geolocate/media/images/icons/wire-globe/white/icon32.png"><img height=22 src="https://raw.githubusercontent.com/adamlui/js-utils/main/geolocate/media/images/icons/wire-globe/black/icon32.png"></picture> [geolocate](https://js-utils.com/geolocate)
|
|
314
315
|
|
|
315
316
|
> Fetch IP geolocation data from the CLI.
|
|
316
317
|
<br>[Install](https://github.com/adamlui/js-utils/tree/main/geolocate#-installation) /
|
|
@@ -323,6 +324,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
323
324
|
|
|
324
325
|
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
325
326
|
|
|
326
|
-
<picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/white/icon32x27.png"><img height=
|
|
327
|
+
<picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/white/icon32x27.png"><img height=13 src="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/dark-gray/icon32x27.png"></picture> <a href="https://js-utils.com">**More JavaScript utilities**</a> /
|
|
327
328
|
<a href="https://js-utils.com/discussions">Discuss</a> /
|
|
328
329
|
<a href="#-generate-pw">Back to top ↑</a>
|
package/dist/cli.min.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const e=require(__dirname.match(/src/)?"./generate-pw":"./generate-pw.min")["generatePassword"],
|
|
2
|
+
const e="https://github.com/adamlui/js-utils/tree/main/generate-pw#-command-line-usage",s=require(__dirname.match(/src/)?"./generate-pw":"./generate-pw.min")["generatePassword"],r=require("child_process")["execSync"],n="[0m",a="[1;91m",t="[1;33m",l={},c={paramOptions:{length:/^--?length(?:=.*|$)/,qty:/^--?qu?a?n?ti?t?y(?:=.*|$)/,charset:/^--?chars(?:=.*|$)/,excludeChars:/^--?exclude(?:=.*|$)/},flags:{includeNums:/^--?(?:n|(?:include-?)?num(?:ber)?s?=?(?:true|1)?)$/,includeSymbols:/^--?(?:s|(?:include-?)?symbols?=?(?:true|1)?)$/,excludeLowerChars:/^--?(?:L|(?:exclude|disable|no)-?lower-?(?:case)?|lower-?(?:case)?=(?:false|0))$/,excludeUpperChars:/^--?(?:U|(?:exclude|disable|no)-?upper-?(?:case)?|upper-?(?:case)?=(?:false|0))$/,strictMode:/^--?s(?:trict)?(?:-?mode)?$/,quietMode:/^--?q(?:uiet)?(?:-?mode)?$/},infoCmds:{help:/^--?h(?:elp)?$/,version:/^--?ve?r?s?i?o?n?$/}};if(process.argv.forEach(s=>{var e,r,o;s.startsWith("-")&&(e=Object.keys(c.paramOptions).find(e=>c.paramOptions[e].test(s)),o=Object.keys(c.flags).find(e=>c.flags[e].test(s)),r=Object.keys(c.infoCmds).find(e=>c.infoCmds[e].test(s)),o?l[o]=!0:e?(s.includes("=")||(console.error(`
|
|
3
|
+
${a}ERROR: Arg [--${s.replace(/-/g,"")}] requires '=' followed by a value.`+n),p(),process.exit(1)),o=s.split("=")[1],l[e]=parseInt(o)||o):r||(console.error(`
|
|
3
4
|
${a}ERROR: Arg [${s}] not recognized.`+n),console.info(`
|
|
4
|
-
${t}Valid arguments are below.`+n),i(["paramOptions","flags","infoCmds"]),process.exit(1)))}),process.argv.some(e=>c.infoCmds.help.test(e)))i();else if(process.argv.some(e=>c.infoCmds.version.test(e)))console.info("v"+require("./package.json").version);else{for(const
|
|
5
|
-
${a}Error: [${
|
|
6
|
-
${t}generate-pw [options|commands]`+n],paramOptions:["\nParameter options:"," --length=n Generate password(s) of n length."," --qty=n Generate n password(s)."," --charset=chars Only include chars in password(s)."," --exclude=chars Exclude chars from password(s)."],flags:["\nBoolean options:"," -n, --include-numbers Allow numbers in password(s)."," -s, --include-symbols Allow symbols in password(s)."," -L, --no-lowercase Disallow lowercase letters in password(s)."," -U, --no-uppercase Disallow uppercase letters in password(s)."," -s, --strict Require at least one character from each allowed character set in password(s)."," -q, --quiet Suppress all logging except errors."],infoCmds:["\nInfo commands:"," -h, --help Display help screen."," -v, --version Show version number."]};e.forEach(e=>{s[e]?.forEach(e=>{{const o=process.stdout.columns||80,n=[],s=e.match(/\S+|\s+/g);let r="";s.forEach(e=>{var s=o-(0===n.length?0:29);r.length+e.length>s&&(n.push(0===n.length?r:r.trimStart()),r=""),r+=e}),n.push(0===n.length?r:r.trimStart()),n.forEach((e,s)=>console.info(0===s?e:" ".repeat(29)+e))}})})}function
|
|
5
|
+
${t}Valid arguments are below.`+n),i(["paramOptions","flags","infoCmds"]),p(),process.exit(1)))}),process.argv.some(e=>c.infoCmds.help.test(e)))i();else if(process.argv.some(e=>c.infoCmds.version.test(e)))console.info("v"+require("./package.json").version);else{for(const u of["length","qty"])l[u]&&(isNaN(l[u])||l[u]<1)&&(console.error(`
|
|
6
|
+
${a}Error: [${u}] argument can only be > 0.`+n),p(),process.exit(1));const d={length:l.length||8,qty:l.qty||1,charset:l.charset,exclude:l.excludeChars,numbers:!!l.includeNums,symbols:!!l.includeSymbols,lowercase:!l.excludeLowerChars,uppercase:!l.excludeUpperChars,strict:!!l.strictMode,verbose:!l.quietMode},m=s(d);l.quietMode||console.info("\nCopying to clipboard..."),o(Array.isArray(m)?m.join("\n"):m)}function i(e=["cmdFormat","paramOptions","flags","infoCmds"]){const s={cmdFormat:[`
|
|
7
|
+
${t}generate-pw [options|commands]`+n],paramOptions:["\nParameter options:"," --length=n Generate password(s) of n length."," --qty=n Generate n password(s)."," --charset=chars Only include chars in password(s)."," --exclude=chars Exclude chars from password(s)."],flags:["\nBoolean options:"," -n, --include-numbers Allow numbers in password(s)."," -s, --include-symbols Allow symbols in password(s)."," -L, --no-lowercase Disallow lowercase letters in password(s)."," -U, --no-uppercase Disallow uppercase letters in password(s)."," -s, --strict Require at least one character from each allowed character set in password(s)."," -q, --quiet Suppress all logging except errors."],infoCmds:["\nInfo commands:"," -h, --help Display help screen."," -v, --version Show version number."]};e.forEach(e=>{s[e]?.forEach(e=>{{const o=process.stdout.columns||80,n=[],s=e.match(/\S+|\s+/g);let r="";s.forEach(e=>{var s=o-(0===n.length?0:29);r.length+e.length>s&&(n.push(0===n.length?r:r.trimStart()),r=""),r+=e}),n.push(0===n.length?r:r.trimStart()),n.forEach((e,s)=>console.info(0===s?e:" ".repeat(29)+e))}})})}function p(){console.info(`
|
|
8
|
+
${t}For more help, type 'generate-pw --help' or visit
|
|
9
|
+
`+(e+n))}function o(e){e=e.replace(/\s+$/m,"").replace(/"/g,'""'),"darwin"===process.platform?r(`printf "${e}" | pbcopy`):"linux"===process.platform?r(`printf "${e}" | xclip -selection clipboard`):"win32"===process.platform&&r(`Set-Clipboard -Value "${e}"`,{shell:"powershell"})}
|
package/dist/generate-pw.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let
|
|
1
|
+
let g;try{({randomInt:g}=require("crypto"))}catch(e){const o=window.crypto||window.msCrypto;g=(e,r)=>{var s=o?.getRandomValues(new Uint32Array(1))[0]/4294967295||Math.random();return Math.floor(s*(r-e))+e}}const h={lower:"abcdefghijklmnopqrstuvwxyz",upper:"ABCDEFGHIJKLMNOPQRSTUVWXYZ",numbers:"0123456789",symbols:"!@#$%^&*()-_=+[]{}/\\|;:'\",.<>?"};function a(o={}){var e={verbose:!0,length:8,qty:1,charset:"",exclude:"",numbers:!1,symbols:!1,lowercase:!0,uppercase:!0,strict:!1};if(m(o,e,"https://github.com/adamlui/js-utils/tree/main/generate-pw#generatepasswordoptions","generatePassword({ verbose: false, numbers: true })")){if(1<(o={...e,...o}).qty){const{qty:r,...s}=o;return i(r,s)}{var t,e="generatePasswords"===a.caller?.name;o.verbose&&!e&&console.info("generatePassword() » Initializing character set...");let r=o.charset||(o.numbers?h.numbers:"")+(o.symbols?h.symbols:"")+(o.lowercase?h.lower:"")+(o.uppercase?h.upper:""),s=(""===r&&(r=h.lower+h.upper),o.exclude&&(o.verbose&&!e&&console.info("generatePassword() » Removing excluded characters..."),r=r.replace(new RegExp(`[${o.exclude}]`,"g"),"")),o.verbose&&!e&&console.info("generatePassword() » Generating password..."),"");for(let e=0;e<o.length;e++){var n=g(0,r.length);s+=r.charAt(n)}return o.strict&&(o.verbose&&!e&&console.info("generatePassword() » Enforcing strict mode..."),t=["number","symbol","lower","upper"].filter(e=>o[e+"s"]||o[e+"case"]),s=l(s,t)),o.verbose&&!e&&(console.info("generatePassword() » Password generated!"),"undefined"!=typeof require&&require.main.filename.endsWith("cli.js")||console.info("generatePassword() » Check returned string.")),s}}}function i(r,s={}){var e="https://github.com/adamlui/js-utils/tree/main/generate-pw#generatepasswordsqty-options",o={verbose:!0,length:8,charset:"",exclude:"",numbers:!1,symbols:!1,lowercase:!0,uppercase:!0,strict:!1};if(r=parseInt(r,10),isNaN(r)||r<1)console.error("generatePasswords() » ERROR: 1st arg <qty> can only be an integer > 0."),console.info("generatePasswords() » For more help, please visit "+e);else if(m(s,o,e,"generatePasswords(3, { verbose: false, symbols: true })")){(s={...o,...s}).verbose&&console.info(`generatePasswords() » Generating password${1<r?"s":""}...`);var t=[];for(let e=0;e<r;e++)t.push(a(s));return s.verbose&&console.info(`generatePasswords() » Password${1<r?"s":""} generated!`),"undefined"!=typeof require&&require.main.filename.endsWith("cli.js")||console.info("generatePasswords() » Check returned array."),t}}function l(o,t=["number","symbol","lower","upper"],e={}){var r="https://github.com/adamlui/js-utils/tree/main/generate-pw#strictifypassword-requiredchartypes-options",n={verbose:!0};if("string"!=typeof o)console.error("strictify() » ERROR: 1st arg <password> must be a string."),console.info("strictify() » For more help, please visit "+r);else{var s=["number","symbol","lower","upper"];for(const f of t=Array.isArray(t)?t:[t])if(!s.includes(f))return console.error(`strictify() » ERROR: 2nd arg \`${f}\` is an invalid character type.`),console.info(`strictify() » Valid character types: [ ${s.map(e=>`'${e}'`).join(", ")} ]`),console.info("strictify() » Pass one as a string or more as an array, or all types will be required."),void console.info("strictify() » For more help, please visit "+r);if(m(e,n,r,"strictify('pa55word', ['symbol', 'upper'], { verbose: false })")){e={...n,...e};var a={};for(const p of t)a["has"+p.charAt(0).toUpperCase()+p.slice(1)]=!1;for(let e=0;e<o.length;e++)for(const d of t)(h[d]||h[d+"s"]).includes(o.charAt(e))&&(a["has"+d.charAt(0).toUpperCase()+d.slice(1)]=!0);e.verbose&&console.info("strictify() » Strictifying password...");var i=Math.min(o.length,t.length),l=[];let r=0,s=o;for(const u of t)if(r<i&&!a["has"+u.charAt(0).toUpperCase()+u.slice(1)]){let e;for(;e=g(0,o.length),l.includes(e););l.push(e);var c=h[u]||h[u+"s"];s=s.substring(0,e)+c.charAt(g(0,c.length))+s.substring(e+1),r++}return e.verbose&&(0<r?(console.info("strictify() » Password is now strict!"),console.info("strictify() » Check returned string.")):(console.info(`strictify() » Password already includes ${t.join(" + ")} characters!`),console.info("strictify() » No modifications made."))),s}}}function e(r,s={}){var e="https://github.com/adamlui/js-utils/tree/main/generate-pw#validatestrengthpassword-options",o={minLength:8,minLower:1,minUpper:1,minNumber:1,minSymbol:1},t={verbose:!0};if("string"!=typeof r)console.error("validateStrength() » ERROR: 1st arg <password> must be a string."),console.info("validateStrength() » For more help, please visit "+e);else if(m(s,t,e,"validateStrength('pa55word', { verbose: false })")){(s={...t,...s}).verbose&&console.info("validateStrength() » Validating password strength...");var n={lower:0,upper:0,number:0,symbol:0};for(const i of r)for(const l of Object.keys(n))(h[l]||h[l+"s"]).includes(i)&&n[l]++;var a=[];r.length<o.minLength&&a.push(`Make it at least ${o.minLength} characters long.`);for(const c of Object.keys(n))n[c]<o["min"+c.charAt(0).toUpperCase()+c.slice(1)]&&a.push("Include at least one "+c+`${["upper","lower"].includes(c)?"case letter":""}.`);let e=0;e+=r.length>=o.minLength?20:0;for(const f of Object.keys(n))e+=n[f]>=o["min"+f.charAt(0).toUpperCase()+f.slice(1)]?20:0;return s.verbose&&(console.info("validateStrength() » Password strength validated!"),console.info("validateStrength() » Check returned object for score/recommendations.")),{strengthScore:e,recommendations:a,isGood:80<=e}}}function m(e,r,s,o){const t=JSON.stringify(r,null,2).replace(/"([^"]+)":/g,"$1:").replace(/"/g,"'").replace(/\n\s*/g," "),n=Object.keys(r).join(", "),a=Object.keys(r).filter(e=>"boolean"==typeof r[e]),i=Object.keys(r).filter(e=>Number.isInteger(r[e])),l=(m.caller?.name||"validateOptions")+"() » ";var c=()=>{console.info(l+`Valid options: [ ${n} ]`),console.info(l+"If omitted, default settings are: "+t)},f=()=>{console.info(l+"For more help, please visit "+s)};if("object"!=typeof e)return console.error(l+"ERROR: [options] can only be an object of key/values."),console.info(l+"Example valid call: "+o),c(),f(),!1;for(const p in e){if(!Object.prototype.hasOwnProperty.call(r,p))return console.error(l+`ERROR: \`${p}\` is an invalid option.`),c(),f(),!1;if(a.includes(p)&&"boolean"!=typeof e[p])return console.error(l+`ERROR: [${p}] option can only be \`true\` or \`false\`.`),f(),!1;if(i.includes(p)&&(e[p]=parseInt(e[p],10),isNaN(e[p])||e[p]<1))return console.error(l+`ERROR: [${p}] option can only be an integer > 0.`),f(),!1}return!0}const r={generatePassword:a,generatePasswords:i,strictify:l,validateStrength:e};try{module.exports={...r}}catch(e){}try{window.pw={...r}}catch(e){}
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
<div align="right">
|
|
2
|
+
<h6>
|
|
3
|
+
<picture>
|
|
4
|
+
<source type="image/svg+xml" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/white/icon32.svg">
|
|
5
|
+
<img height=14 src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/earth-icon/black/icon32.svg">
|
|
6
|
+
</picture>
|
|
7
|
+
English |
|
|
8
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/generate-pw/docs/zh-cn#readme">简体中文</a> |
|
|
9
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/generate-pw/docs/zh-tw#readme">繁體中文</a> |
|
|
10
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/generate-pw/docs/hi#readme">हिंदी</a> |
|
|
11
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/generate-pw/docs/bn#readme">বাংলা</a> |
|
|
12
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/generate-pw/docs/de#readme">Deutsch</a> |
|
|
13
|
+
<a href="https://github.com/adamlui/js-utils/tree/main/generate-pw/docs/es#readme">Español</a>
|
|
14
|
+
</h6>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
# > generate-pw
|
|
18
|
+
|
|
19
|
+
### Randomly generate, strengthen, and validate cryptographically-secure passwords.
|
|
20
|
+
|
|
21
|
+
<a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
22
|
+
<a href="https://github.com/adamlui/js-utils/releases/tag/generate-pw-1.4.4"><img height=31 src="https://img.shields.io/badge/Latest_Build-1.4.4-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
23
|
+
<a href="https://www.npmjs.com/package/generate-pw?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/generate-pw?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
|
|
24
|
+
<a href="https://github.com/adamlui/js-utils/blob/generate-pw-1.4.4/generate-pw/dist/generate-pw.min.js"><img height=31 src="https://img.shields.io/github/size/adamlui/js-utils/generate-pw/dist/generate-pw.min.js?branch=generate-pw-1.4.4&label=Minified%20Size&logo=databricks&logoColor=white&labelColor=464646&color=ff69b4&style=for-the-badge"></a>
|
|
25
|
+
<a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:generate-pw/src/generate-pw.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Agenerate-pw%2Fsrc%2Fgenerate-pw.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
|
|
26
|
+
<a href="https://github.com/toolleeo/cli-apps#password-managers"><img height=31 src="https://img.shields.io/badge/Mentioned_in-Awesome-c4a2bd?logo=awesomelists&logoColor=white&labelColor=464646&style=for-the-badge"></a>
|
|
27
|
+
|
|
28
|
+
<br>
|
|
29
|
+
|
|
30
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
31
|
+
|
|
32
|
+
## 💡 About
|
|
33
|
+
|
|
34
|
+
**generate-pw** is a lightweight, easy-to-use library that allows you to randomly generate, strengthen & validate cryptographically-secure password(s).
|
|
35
|
+
|
|
36
|
+
- **No external dependencies —** Only built-in crypto methods used for secure randomization
|
|
37
|
+
- **Highly customizable —** Specify length, quantity, charsets to use, etc.
|
|
38
|
+
- **Multi-environment support —** Use in Node.js or the web browser
|
|
39
|
+
- **Command line usable —** Just type `generate-pw`, that's it
|
|
40
|
+
|
|
41
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
42
|
+
|
|
43
|
+
## ⚡ Installation
|
|
44
|
+
|
|
45
|
+
As a **global utility**:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
$ npm install -g generate-pw
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
As a **runtime dependency**, from your project root:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
$ npm install generate-pw
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
<br>
|
|
58
|
+
|
|
59
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
60
|
+
|
|
61
|
+
## 🔌 Importing the API
|
|
62
|
+
|
|
63
|
+
### <img height=18 src="https://i.imgur.com/JIeAdsr.png"> Node.js
|
|
64
|
+
|
|
65
|
+
#### ECMAScript*:
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
import * as pw from 'generate-pw';
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### CommonJS:
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
const pw = require('generate-pw');
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
###### _*Node.js version 14 or higher required_
|
|
78
|
+
|
|
79
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://i.imgur.com/JSEb19A.png"><img width=16 src="https://i.imgur.com/5VPxf9y.png"></picture> Web
|
|
80
|
+
|
|
81
|
+
#### <> HTML script tag:
|
|
82
|
+
|
|
83
|
+
```html
|
|
84
|
+
<script src="https://cdn.jsdelivr.net/npm/generate-pw@1.4.4/dist/generate-pw.min.js"></script>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### ES6:
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
(async () => {
|
|
91
|
+
await import('https://cdn.jsdelivr.net/npm/generate-pw@1.4.4/dist/generate-pw.min.js');
|
|
92
|
+
// Your code here...
|
|
93
|
+
})();
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### <img height=17 src="https://raw.githubusercontent.com/KudoAI/chatgpt.js/main/starters/media/images/icons/tampermonkey-icon28.png"><img height=17.5 src="https://raw.githubusercontent.com/KudoAI/chatgpt.js/main/starters/media/images/icons/violentmonkey-icon100.png"> Greasemonkey
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
...
|
|
100
|
+
// @require https://cdn.jsdelivr.net/npm/generate-pw@1.4.4/dist/generate-pw.min.js
|
|
101
|
+
// ==/UserScript==
|
|
102
|
+
|
|
103
|
+
// Your code here...
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
<br>
|
|
107
|
+
|
|
108
|
+
**💡 Note:** To always import the latest version (not recommended in production!) remove the `@1.4.4` version tag from the jsDelivr URL: `https://cdn.jsdelivr.net/npm/generate-pw/dist/generate-pw.min.js`
|
|
109
|
+
|
|
110
|
+
<br>
|
|
111
|
+
|
|
112
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
113
|
+
|
|
114
|
+
## 📋 API usage
|
|
115
|
+
|
|
116
|
+
### `generatePassword([options])`
|
|
117
|
+
|
|
118
|
+
Generates **one** password if `qty` option is not given, returning a string:
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
const password = pw.generatePassword({ length: 11, numbers: true });
|
|
122
|
+
console.log(password); // sample output: 'bAsZm3mq6Qn'
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
...or **multiple** passwords if `qty` option is given, returning an array of strings:
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
const passwords = pw.generatePassword({ qty: 5, length: 8, symbols: true });
|
|
129
|
+
console.log(passwords);
|
|
130
|
+
|
|
131
|
+
/* sample output:
|
|
132
|
+
|
|
133
|
+
generatePassword() » Generating passwords...
|
|
134
|
+
generatePassword() » Passwords generated!
|
|
135
|
+
generatePassword() » Check returned array.
|
|
136
|
+
[ '!zSf@Q.s', '!,HT\\;m=', '?Lq&FV>^', 'gf}Y;}Ne', 'Stsx(GqE' ]
|
|
137
|
+
*/
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**💡 Note:** If no options are passed, passwords will be 8-chars long, consisting of upper/lower cased letters.
|
|
141
|
+
|
|
142
|
+
See: [Available options](#available-options-for-generate-functions)
|
|
143
|
+
|
|
144
|
+
#
|
|
145
|
+
|
|
146
|
+
### `generatePasswords(qty[, options])`
|
|
147
|
+
|
|
148
|
+
Generates **multiple** passwords based on `qty` given, returning an array of strings:
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
const passwords = pw.generatePasswords(5, { length: 3, uppercase: false });
|
|
152
|
+
console.log(passwords);
|
|
153
|
+
|
|
154
|
+
/* sample output:
|
|
155
|
+
|
|
156
|
+
generatePasswords() » Generating passwords...
|
|
157
|
+
generatePasswords() » Passwords generated!
|
|
158
|
+
generatePasswords() » Check returned array.
|
|
159
|
+
[ 'yilppxru', 'ckvkyjfp', 'zolcpyfb' ]
|
|
160
|
+
*/
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**💡 Note:** If no `qty` arg is passed, just one password will be generated, returned as a string.
|
|
164
|
+
|
|
165
|
+
See: [Available options](#available-options-for-generate-functions)
|
|
166
|
+
|
|
167
|
+
#
|
|
168
|
+
|
|
169
|
+
### `strictify(password[, requiredCharTypes, options])`
|
|
170
|
+
|
|
171
|
+
Modifies `password` given to use at least one character of each `requiredCharTypes` element passed, returning a string:
|
|
172
|
+
|
|
173
|
+
```js
|
|
174
|
+
const strictPW = pw.strictify('abcdef', ['numbers', 'symbols']);
|
|
175
|
+
console.log(strictPW); // sample output: 'a!c2ef'
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**💡 Note:** If no `requiredCharTypes` array is passed, all available types will be required.
|
|
179
|
+
|
|
180
|
+
Available `requiredCharTypes` are: `['number', 'symbol', 'lower', 'upper']`
|
|
181
|
+
|
|
182
|
+
Available options (passed as object properties):
|
|
183
|
+
|
|
184
|
+
Name | Type | Description | Default Value
|
|
185
|
+
----------|---------|-----------------------------------|---------------
|
|
186
|
+
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
187
|
+
|
|
188
|
+
#
|
|
189
|
+
|
|
190
|
+
### `validateStrength(password[, options])`
|
|
191
|
+
|
|
192
|
+
Validates the strength of a password, returning an object containing:
|
|
193
|
+
- `strengthScore` (0–100)
|
|
194
|
+
- `recommendations` array
|
|
195
|
+
- `isGood` boolean (`true` if `strengthScore` >= 80)
|
|
196
|
+
|
|
197
|
+
Example:
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
const pwStrength = pw.validateStrength('Aa?idsE');
|
|
201
|
+
console.log(pwStrength);
|
|
202
|
+
|
|
203
|
+
/* outputs:
|
|
204
|
+
|
|
205
|
+
validateStrength() » Validating password strength...
|
|
206
|
+
validateStrength() » Password strength validated!
|
|
207
|
+
validateStrength() » Check returned object for score/recommendations.
|
|
208
|
+
{
|
|
209
|
+
strengthScore: 60,
|
|
210
|
+
recommendations: [
|
|
211
|
+
'Make it at least 8 characters long.',
|
|
212
|
+
'Include at least one number.'
|
|
213
|
+
],
|
|
214
|
+
isGood: false
|
|
215
|
+
}
|
|
216
|
+
*/
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Available options (passed as object properties):
|
|
220
|
+
|
|
221
|
+
Name | Type | Description | Default Value
|
|
222
|
+
----------|---------|-----------------------------------|---------------
|
|
223
|
+
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
224
|
+
|
|
225
|
+
#
|
|
226
|
+
|
|
227
|
+
### Available options for `generate*()` functions
|
|
228
|
+
|
|
229
|
+
Any of these can be passed into the options object for each `generate*()` function:
|
|
230
|
+
|
|
231
|
+
Name | Type | Description | Default Value
|
|
232
|
+
------------|---------|--------------------------------------------------------------------------------|---------------
|
|
233
|
+
`verbose` | Boolean | Show logging in console/terminal. | `true`
|
|
234
|
+
`length` | Integer | Length of password(s). | `8`
|
|
235
|
+
`qty`* | Integer | Number of passwords to generate. | `1`
|
|
236
|
+
`charset` | String | Characters to include in password(s). | `''`
|
|
237
|
+
`exclude` | String | Characters to exclude from password(s). | `''`
|
|
238
|
+
`numbers` | Boolean | Allow numbers in password(s). | `false`
|
|
239
|
+
`symbols` | Boolean | Allow symbols in password(s). | `false`
|
|
240
|
+
`lowercase` | Boolean | Allow lowercase letters in password(s). | `true`
|
|
241
|
+
`uppercase` | Boolean | Allow uppercase letters in password(s). | `true`
|
|
242
|
+
`strict` | Boolean | Require at least one character from each allowed character set in password(s). | `false`
|
|
243
|
+
|
|
244
|
+
##### _*Only available in [`generatePassword([options])`](#generatepasswordoptions) since [`generatePasswords(qty[, options])`](#generatepasswordsqty-options) takes a `qty` argument_
|
|
245
|
+
|
|
246
|
+
<br>
|
|
247
|
+
|
|
248
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
249
|
+
|
|
250
|
+
## 💻 Command line usage
|
|
251
|
+
|
|
252
|
+
When installed [globally](#-installation), **generate-pw** can also be used from the command line. The basic command is:
|
|
253
|
+
|
|
254
|
+
```
|
|
255
|
+
$ generate-pw
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**💡 Note:** For security reasons, generated password(s) are stored in the clipboard.
|
|
259
|
+
|
|
260
|
+
#
|
|
261
|
+
|
|
262
|
+
### Command line options
|
|
263
|
+
|
|
264
|
+
```
|
|
265
|
+
Parameter options:
|
|
266
|
+
--length=n Generate password(s) of n length.
|
|
267
|
+
--qty=n Generate n password(s).
|
|
268
|
+
--charset=chars Only include chars in password(s).
|
|
269
|
+
--exclude=chars Exclude chars from password(s).
|
|
270
|
+
|
|
271
|
+
Boolean options:
|
|
272
|
+
-n, --include-numbers Allow numbers in password(s).
|
|
273
|
+
-s, --include-symbols Allow symbols in password(s).
|
|
274
|
+
-L, --no-lowercase Disallow lowercase letters in password(s).
|
|
275
|
+
-U, --no-uppercase Disallow uppercase letters in password(s).
|
|
276
|
+
-s, --strict Require at least one character from each
|
|
277
|
+
allowed character set in password(s).
|
|
278
|
+
-q, --quiet Suppress all logging except errors.
|
|
279
|
+
|
|
280
|
+
Info commands:
|
|
281
|
+
-h, --help Display help screen.
|
|
282
|
+
-v, --version Show version number.
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
<br>
|
|
286
|
+
|
|
287
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
288
|
+
|
|
289
|
+
## 🏛️ MIT License
|
|
290
|
+
|
|
291
|
+
**Copyright © 2024 [Adam Lui](https://github.com/adamlui) & contributors.**
|
|
292
|
+
|
|
293
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
294
|
+
|
|
295
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
296
|
+
|
|
297
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
298
|
+
|
|
299
|
+
<br>
|
|
300
|
+
|
|
301
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
302
|
+
|
|
303
|
+
## 🛠️ Related utilities
|
|
304
|
+
|
|
305
|
+
### <img height=21px src="https://i.imgur.com/kvf7fXm.png"> [generate-ip](https://js-utils.com/generate-ip) <a href="https://github.com/toolleeo/cli-apps#networking"><img height=18 src="https://awesome.re/mentioned-badge.svg"></a>
|
|
306
|
+
|
|
307
|
+
> Randomly generate, format, and validate IPv4/IPv6 addresses.
|
|
308
|
+
<br>[Install](https://github.com/adamlui/js-utils/tree/main/generate-ip#-installation) /
|
|
309
|
+
[Readme](https://github.com/adamlui/js-utils/tree/main/generate-ip#readme) /
|
|
310
|
+
[API usage](https://github.com/adamlui/js-utils/tree/main/generate-ip#-api-usage) /
|
|
311
|
+
[CLI usage](https://github.com/adamlui/js-utils/tree/main/generate-ip#-command-line-usage) /
|
|
312
|
+
[Discuss](https://js-utils.com/discussions)
|
|
313
|
+
|
|
314
|
+
### <picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/geolocate/media/images/icons/wire-globe/white/icon32.png"><img height=22 src="https://raw.githubusercontent.com/adamlui/js-utils/main/geolocate/media/images/icons/wire-globe/black/icon32.png"></picture> [geolocate](https://js-utils.com/geolocate)
|
|
315
|
+
|
|
316
|
+
> Fetch IP geolocation data from the CLI.
|
|
317
|
+
<br>[Install](https://github.com/adamlui/js-utils/tree/main/geolocate#-installation) /
|
|
318
|
+
[Readme](https://github.com/adamlui/js-utils/tree/main/geolocate#readme) /
|
|
319
|
+
[CLI usage](https://github.com/adamlui/js-utils/tree/main/geolocate#-command-line-usage) /
|
|
320
|
+
[API usage](https://github.com/adamlui/js-utils/tree/main/geolocate#-api-usage) /
|
|
321
|
+
[Discuss](https://js-utils.com/discussions)
|
|
322
|
+
|
|
323
|
+
<br>
|
|
324
|
+
|
|
325
|
+
<img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
|
|
326
|
+
|
|
327
|
+
<picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/white/icon32x27.png"><img height=13 src="https://raw.githubusercontent.com/adamlui/js-utils/main/media/images/icons/home/dark-gray/icon32x27.png"></picture> <a href="https://js-utils.com">**More JavaScript utilities**</a> /
|
|
328
|
+
<a href="https://js-utils.com/discussions">Discuss</a> /
|
|
329
|
+
<a href="#-generate-pw">Back to top ↑</a>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generate-pw",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Randomly generate, strengthen, and validate cryptographically-secure passwords.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Adam Lui",
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"url": "https://github.com/sponsors/adamlui"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@adamlui/minify.js": "^1.
|
|
56
|
+
"@adamlui/minify.js": "^1.5.0"
|
|
57
57
|
}
|
|
58
58
|
}
|