0.0.5 • Published 11 months ago

@kennx9/random-password v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Random Password Generator | 随机密码生成器

A versatile random password generator for Node.js and browser.

一个适用于 Node.js 和浏览器的多功能随机密码生成器。

Features | 特性

  • Generate secure random passwords | 生成安全的随机密码
  • Customizable password length and character sets | 可自定义密码长度和字符集
  • Password strength evaluation | 密码强度评估
  • Support for both Node.js and browser environments | 同时支持 Node.js 和浏览器环境
  • Command-line interface (CLI) support | 支持命令行界面
  • Flexible configuration options | 灵活的配置选项
  • TypeScript support | 支持 TypeScript

Installation | 安装

npm install @kennx9/random-password
# or
pnpm add @kennx9/random-password
# or
yarn add @kennx9/random-password

Usage | 使用方法

As a Module | 作为模块使用

import { generatePassword } from '@kennx9/random-password';

// Generate password with default options
// 使用默认选项生成密码
const { password, strength } = generatePassword();
console.log(password);  // e.g., "Kj#9mP$2nL5q"
console.log(strength);  // "strong"

// Generate password with custom options
// 使用自定义选项生成密码
const result = generatePassword({
  length: 16,                // Password length | 密码长度
  numbers: true,             // Include numbers | 包含数字
  symbols: true,             // Include symbols | 包含符号
  uppercase: true,           // Include uppercase letters | 包含大写字母
  lowercase: true,           // Include lowercase letters | 包含小写字母
  firstCharacter: 'random',  // First character type | 首字符类型
  excludeChars: {           // Characters to exclude | 要排除的字符
    lowercase: ['l', 'o'],
    uppercase: ['I', 'O'],
    numbers: ['0', '1'],
    symbols: ['@', '#']
  },
  customCharset: undefined   // Custom character set | 自定义字符集
});

Command Line Usage | 命令行使用

The package includes a CLI tool named 'rnd'.

包含一个名为 'rnd' 的命令行工具。

# Basic usage | 基本使用
rnd

# Generate a 16-character password | 生成16位密码
rnd -l 16

# Generate 5 passwords | 生成5个密码
rnd -c 5

# Generate password with verbose output | 生成密码并显示详细信息
rnd -v

# Exclude specific characters | 排除特定字符
rnd --exclude-lowercase "l,o" --exclude-numbers "0,1"

# Use custom character set | 使用自定义字符集
rnd --custom-charset "abcdefghijklmnopqrstuvwxyz0123456789"

CLI Options | 命令行选项

OptionDescription描述
-l, --length \Password length (4-128)密码长度 (4-128)
-c, --count \Number of passwords to generate生成密码的数量
-v, --verboseShow detailed password information显示详细的密码信息
--no-numbersExclude numbers排除数字
--no-symbolsExclude symbols排除符号
--no-uppercaseExclude uppercase letters排除大写字母
--no-lowercaseExclude lowercase letters排除小写字母
--exclude-lowercase \Exclude specific lowercase letters排除特定小写字母
--exclude-uppercase \Exclude specific uppercase letters排除特定大写字母
--exclude-numbers \Exclude specific numbers排除特定数字
--exclude-symbols \Exclude specific symbols排除特定符号
--custom-charset \Use custom character set使用自定义字符集

API Reference | API 参考

generatePassword(options?)

Generate a random password based on the provided options.

根据提供的选项生成随机密码。

Options | 选项

interface PasswordOptions {
  length?: number;           // Password length | 密码长度
  numbers?: boolean;         // Include numbers | 包含数字
  symbols?: boolean;         // Include symbols | 包含符号
  uppercase?: boolean;       // Include uppercase | 包含大写字母
  lowercase?: boolean;       // Include lowercase | 包含小写字母
  firstCharacter?: FirstCharacterType;  // First character type | 首字符类型
  excludeChars?: {          // Characters to exclude | 要排除的字符
    lowercase?: string[];
    uppercase?: string[];
    numbers?: string[];
    symbols?: string[];
  };
  customCharset?: string;    // Custom character set | 自定义字符集
}

Return Value | 返回值

{
  password: string;          // Generated password | 生成的密码
  strength: PasswordStrength // Password strength (weak/medium/strong) | 密码强度 (弱/中/强)
}

License | 许可证

MIT

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.1

11 months ago