Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaywcjlove/generate-password
Generate Password is a generating random and unique passwords.
https://github.com/jaywcjlove/generate-password
generator password password-generator
Last synced: 3 months ago
JSON representation
Generate Password is a generating random and unique passwords.
- Host: GitHub
- URL: https://github.com/jaywcjlove/generate-password
- Owner: jaywcjlove
- License: mit
- Created: 2022-06-12T08:46:31.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-23T16:57:48.000Z (5 months ago)
- Last Synced: 2024-10-29T11:29:16.454Z (3 months ago)
- Topics: generator, password, password-generator
- Language: TypeScript
- Homepage: https://jaywcjlove.github.io/generate-password
- Size: 16.7 MB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Generate Password
[![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor)
![No Dependencies](http://jaywcjlove.github.io/sb/status/no-dependencies.svg)
[![npm package](https://img.shields.io/npm/v/@wcj/generate-password.svg)](https://www.npmjs.com/package/@wcj/generate-password)
[![GitHub Actions CI](https://github.com/jaywcjlove/generate-password/actions/workflows/ci.yml/badge.svg)](https://github.com/jaywcjlove/generate-password/actions/workflows/ci.yml)
[![Coverage Status](https://jaywcjlove.github.io/generate-password/badges.svg)](https://jaywcjlove.github.io/generate-password/lcov-report/)
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/@wcj/generate-password)](https://bundlephobia.com/result?p=@wcj/generate-password)Generate Password is a generating random and unique passwords.
## Install
```bash
$ npm install @wcj/generate-password --save
```## Usage
```js
import { generate, generateMultiple, validate } from '@wcj/generate-password';generate(); // => dK0#vA3@fG
generate({ length: 23 }); // => bB1@aO7^bF0!aA0~aQ1%aE3
generateMultiple(2, { length: 8 }); // => [ 'aG6@aC2(', 'dH0{fQ0%' ]
validate('qK0#dQ3*gG'); // => 4 Strong :) Now it's safe!
```Or manually download and link **generate-password.js** in your HTML, It can also be downloaded via [UNPKG](https://unpkg.com/browse/@wcj/generate-password/):
CDN: [UNPKG](https://unpkg.com/browse/@wcj/generate-password/) | [jsDelivr](https://cdn.jsdelivr.net/npm/@wcj/generate-password/)
```html
GeneratePassword.generate(); // => dK0#vA3@fG
GeneratePassword.generate({ length: 23 }); // => bB1@aO7^bF0!aA0~aQ1%aE3
GeneratePassword.generateMultiple(2, { length: 8 }); // => [ 'aG6@aC2(', 'dH0{fQ0%' ]
GeneratePassword.validate('qK0#dQ3*gG'); // => 4, Strong :) Now it's safe!```
## API
### 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
```## 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
* @return [0~4]
*
* `4` Strong :) Now it's safe!
* `3` Medium level. Enter more symbols!
* `2` Very Weak! It's easy to crack!
* `1` It's easy to crack!
*/
export declare function validate(password?: string): number;
```## Example
```jsx mdx:preview
import React, { useState } from 'react';
import { generate } from '@wcj/generate-password';const Demo = () => {
const [lowerCase, setLowerCase] = useState(true);
const [upperCase, setUpperCase] = useState(true);
const [numeric, setNumeric] = useState(true);
const [special, setSpecial] = useState(true);
const [length, setLength] = useState(8);
const opts = { lowerCase, upperCase, numeric, special, length };
const [password, setPassword] = useState(generate(opts));
return (
{password}
setPassword(generate(opts))}>Generate Password
setLength(Number(evn.target.value))} />{' '}
{length} length of password.
setLowerCase(!lowerCase)} /> Lower Case
Letter(a..z)
setUpperCase(!upperCase)} /> Upper Case
Letter(A..Z)
setNumeric(!numeric)} /> Number (0..9)
setSpecial(!special)} /> Special characters
);
};export default Demo;
```## Development
```bash
npm install # Install dependenciesnpm run build # Build packages
npm run start # Run Websitecd core # Enter the `core` folder
npm run watch
npm run test
```## Contributors
As always, thanks to our amazing contributors!
Made with [contributors](https://github.com/jaywcjlove/github-action-contributors).
## License
Licensed under the MIT License.