-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3bb200d
Showing
19 changed files
with
740 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
coverage | ||
build | ||
node_modules | ||
npm-debug.log* | ||
package-lock.json | ||
dist | ||
cjs | ||
esm | ||
|
||
.eslintcache | ||
.DS_Store | ||
.cache | ||
.vscode | ||
|
||
*.bak | ||
*.tem | ||
*.temp | ||
#.swp | ||
*.*~ | ||
~*.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx --no-install lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package.json | ||
coverage | ||
dist | ||
build | ||
cjs | ||
esm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"printWidth": 120, | ||
"overrides": [ | ||
{ | ||
"files": ".prettierrc", | ||
"options": { "parser": "json" } | ||
}, | ||
{ | ||
"files": ".lintstagedrc", | ||
"options": { "parser": "json" } | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Generate Password | ||
|
||
Generate Password is a generating random and unique passwords. | ||
|
||
## Install | ||
|
||
```bash | ||
$ npm install @wcj/generate-password --save | ||
``` | ||
|
||
## Usage | ||
|
||
### generate | ||
|
||
Create a random password | ||
|
||
```js | ||
import { generate } from '@wcj/generate-password'; | ||
|
||
generate(); // => dK0#vA3@fG | ||
generate({ length: 23 }); // => bB1@aO7^bF0!aA0~aQ1%aE3 | ||
generate({ upperCase: false }); // => n6[a3_f0$k | ||
generate({ lowerCase: false }); // => N0(B3,C4$I | ||
generate({ numeric: false }); // => cX*rB|jP:j | ||
generate({ numeric: false }); // => eD3rA0gL1b | ||
generate({ special: false, numeric: false }); // => aCaLlGfSgI | ||
generate({ special: false, lowerCase: false, upperCase: false }); // => 4020810127 | ||
generate({ special: false, lowerCase: false, numeric: false }); // => DEEBBCBYAO | ||
generate({ lowerCase: false, upperCase: false, numeric: false }); // => !%:#_#*&^! | ||
``` | ||
|
||
### generateMultiple | ||
|
||
Create a random set of passwords | ||
|
||
```js | ||
import { generateMultiple } from '@wcj/generate-password'; | ||
|
||
generateMultiple(); | ||
// [ | ||
// 'qK0#dQ3*gG', 'rQ1#lB0#kE', 'mO1#dH1_tQ', 'gE1$rE2)aJ', | ||
// 'eR6#eJ5|qE', 'rP3!cH1)aK', 'iE0#dB2$iE', 'bC0&mI1#hB', | ||
// 'kB0(eG1!lD', 'bA7>hE4)kA' | ||
// ] | ||
generateMultiple(2, { length: 8 }); // => [ 'aG6@aC2(', 'dH0{fQ0%' ] | ||
``` | ||
|
||
### validate | ||
|
||
symbols pass with lowercase and uppercase letters, numbers and special characters | ||
|
||
```js | ||
import { validate } from '@wcj/generate-password'; | ||
|
||
validate('qK0#dQ3*gG'); // => 4 Strong :) Now it's safe! | ||
validate('n6[a3_f0$k'); // => 3 Medium level. Enter more symbols! | ||
validate('aCaLlGfSgI'); // => 2 Very Weak! It's easy to crack! | ||
validate('4020810127'); // => 1 It's easy to crack! | ||
validate(); // => 0 | ||
``` | ||
|
||
### generateMultiple | ||
|
||
```js | ||
import { generateMultiple } from '@wcj/generate-password'; | ||
|
||
generateMultiple(3); // => [ 'eD5$aA1$dB', 'aB2!gC1#jQ', 'aB1@dK1*mH' ] | ||
generateMultiple(2, { length: 8 }); // => [ 'fJ4@kF3,', 'aE0%gP0;' ] | ||
``` | ||
|
||
## Options | ||
|
||
```ts | ||
export declare const LOWERCASE = 'abcdefghijklmnopqrstuvwxyz'; | ||
export declare const UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
export declare const NUMERIC = '0123456789'; | ||
export declare const SPECIAL_CHARACTER = '!@#$%^&*()_+~`|}{\\[\\]:;?>,.<-=\\/'; | ||
export declare type Option = { | ||
/** | ||
* Integer, length of password. | ||
* @default 10 | ||
*/ | ||
length?: number; | ||
/** Boolean, put lowercase in password */ | ||
lowerCase?: boolean; | ||
/** Boolean, use uppercase letters in password. */ | ||
upperCase?: boolean; | ||
/** Boolean, put numbers in password. */ | ||
numeric?: boolean; | ||
/** Special characters */ | ||
special?: boolean; | ||
}; | ||
/** Create a random password */ | ||
export declare function generate(opts?: Option): string; | ||
/** Create a random set of passwords */ | ||
export declare function generateMultiple(length?: number, opts?: Option): string[]; | ||
/** | ||
* symbols pass with lowercase and uppercase letters, numbers and special characters | ||
*/ | ||
export declare function validate(password: string): number; | ||
``` | ||
|
||
## Development | ||
|
||
```bash | ||
npm install # Install dependencies | ||
|
||
npm run build # Build packages | ||
npm run start # Run Website | ||
|
||
cd core # Enter the `core` folder | ||
npm run watch | ||
npm run test | ||
``` | ||
|
||
## Contributors | ||
|
||
As always, thanks to our amazing contributors! | ||
|
||
<a href="https://github.com/jaywcjlove/generate-password/graphs/contributors"> | ||
<img src="https://jaywcjlove.github.io/generate-password/CONTRIBUTORS.svg" /> | ||
</a> | ||
|
||
Made with [action-contributors](https://github.com/jaywcjlove/github-action-contributors). | ||
|
||
## License | ||
|
||
Licensed under the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "@wcj/generate-password", | ||
"version": "1.0.0", | ||
"description": "Generate Password is a generating random and unique passwords.", | ||
"homepage": "https://jaywcjlove.github.io/generate-password", | ||
"main": "./cjs/index.js", | ||
"module": "./esm/index.js", | ||
"unpkg": "./dist/generate-password.js", | ||
"typings": "./dist/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/jaywcjlove/generate-password.git" | ||
}, | ||
"keywords": [ | ||
"generate-password", | ||
"password" | ||
], | ||
"author": "kenny wong <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "rollup -c rollup.config.js", | ||
"watch": "rollup -c rollup.config.js -w", | ||
"test": "tsbb test", | ||
"coverage": "tsbb test --coverage" | ||
}, | ||
"files": [ | ||
"src", | ||
"cjs", | ||
"esm", | ||
"dist" | ||
], | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "~22.0.0", | ||
"@rollup/plugin-node-resolve": "~13.3.0", | ||
"@rollup/plugin-typescript": "~8.3.2", | ||
"bannerjs": "~2.1.0", | ||
"rollup": "^2.74.1", | ||
"rollup-plugin-terser": "~7.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import typescript from '@rollup/plugin-typescript'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import { nodeResolve } from '@rollup/plugin-node-resolve'; | ||
import { terser } from 'rollup-plugin-terser'; | ||
import banner from 'bannerjs'; | ||
import pkg from './package.json'; | ||
|
||
export default [ | ||
{ | ||
input: 'src/index.ts', | ||
output: [ | ||
{ | ||
file: pkg.main, | ||
format: 'cjs', | ||
name: 'GeneratePassword', | ||
exports: 'auto', | ||
banner: banner.multibanner(), | ||
sourcemap: true, | ||
}, | ||
{ | ||
file: pkg.module, | ||
format: 'es', | ||
name: 'GeneratePassword', | ||
banner: banner.multibanner(), | ||
sourcemap: true, | ||
}, | ||
], | ||
plugins: [ | ||
nodeResolve({ browser: true }), | ||
typescript({ | ||
tsconfig: './tsconfig.json', | ||
exclude: ['node_modules', '../../node_modules'], | ||
}), | ||
commonjs(), | ||
], | ||
}, | ||
{ | ||
input: 'src/index.ts', | ||
output: [ | ||
{ | ||
file: pkg.unpkg, | ||
format: 'umd', | ||
name: 'GeneratePassword', | ||
banner: banner.multibanner(), | ||
sourcemap: false, | ||
}, | ||
], | ||
plugins: [ | ||
typescript({ | ||
tsconfig: './tsconfig.json', | ||
exclude: ['node_modules', '../../node_modules'], | ||
compilerOptions: { | ||
sourceMap: false, | ||
}, | ||
}), | ||
], | ||
}, | ||
{ | ||
input: 'src/index.ts', | ||
output: [ | ||
{ | ||
// file: 'dist/generate-password.min.js', | ||
file: `dist/generate-password.v${pkg.version}.min.js`, | ||
format: 'umd', | ||
name: 'GeneratePassword', | ||
banner: banner.onebanner(), | ||
sourcemap: false, | ||
}, | ||
], | ||
plugins: [ | ||
typescript({ | ||
tsconfig: './tsconfig.json', | ||
exclude: ['node_modules', '../../node_modules'], | ||
compilerOptions: { | ||
sourceMap: false, | ||
}, | ||
}), | ||
terser({}), | ||
], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
export const LOWERCASE = 'abcdefghijklmnopqrstuvwxyz'; | ||
export const UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
export const NUMERIC = '0123456789'; | ||
export const SPECIAL_CHARACTER = '!@#$%^&*()_+~`|}{\\[\\]:;?>,.<-=\\/'; | ||
|
||
export type Option = { | ||
/** | ||
* Integer, length of password. | ||
* @default 10 | ||
*/ | ||
length?: number; | ||
/** Boolean, put lowercase in password */ | ||
lowerCase?: boolean; | ||
/** Boolean, use uppercase letters in password. */ | ||
upperCase?: boolean; | ||
/** Boolean, put numbers in password. */ | ||
numeric?: boolean; | ||
/** Special characters */ | ||
special?: boolean; | ||
}; | ||
|
||
/** Create a random password */ | ||
export function generate(opts: Option = {}) { | ||
const { lowerCase = true, upperCase = true, numeric = true, special = true, length = 10 } = opts; | ||
let password = ''; | ||
if (!lowerCase && !upperCase && !numeric && !special) { | ||
return password; | ||
} | ||
while (password.length < length) { | ||
const entity1 = Math.ceil(LOWERCASE.length * Math.random() * Math.random()) - 1; | ||
const entity2 = Math.ceil(NUMERIC.length * Math.random() * Math.random()) - 1; | ||
const entity3 = Math.ceil(SPECIAL_CHARACTER.length * Math.random() * Math.random()) - 1; | ||
const entity4 = Math.ceil(UPPERCASE.length * Math.random() * Math.random()) - 1; | ||
if (lowerCase && password.length < length) { | ||
password += LOWERCASE.charAt(entity1); | ||
} | ||
if (upperCase && password.length < length) { | ||
password += UPPERCASE.charAt(entity4); | ||
} | ||
if (numeric && password.length < length) { | ||
password += NUMERIC.charAt(entity2); | ||
} | ||
if (special && password.length < length) { | ||
password += SPECIAL_CHARACTER.charAt(entity3); | ||
} | ||
} | ||
return password.trim(); | ||
} | ||
|
||
/** Create a random set of passwords */ | ||
export function generateMultiple(length: number = 10, opts?: Option) { | ||
const result: string[] = []; | ||
[...Array(length)].forEach(() => result.push(generate(opts))); | ||
return result; | ||
} | ||
|
||
/** | ||
* symbols pass with lowercase and uppercase letters, numbers and special characters | ||
*/ | ||
export function validate(password: string = '') { | ||
// Create an array and push all possible values that you want in password | ||
const matchedCase = new Array(); | ||
matchedCase.push(`[${SPECIAL_CHARACTER}]`); // Special Charector | ||
matchedCase.push('[A-Z]'); // Uppercase Alpabates | ||
matchedCase.push('[0-9]'); // Numbers | ||
matchedCase.push('[a-z]'); // Lowercase Alphabates | ||
// Check the conditions | ||
let ctr = 0; | ||
for (let i = 0; i < matchedCase.length; i++) { | ||
if (new RegExp(matchedCase[i]).test(password)) { | ||
ctr++; | ||
} | ||
} | ||
return ctr; | ||
} |
Oops, something went wrong.