password-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Password Generator

密码生成工具

Generate cryptographically secure passwords and memorable passphrases. Customize character sets, length, and rules. Includes strength checking and bulk generation.
生成符合加密安全标准的密码和易记的密码短语。可自定义字符集、长度及规则,包含强度检测与批量生成功能。

Quick Start

快速开始

python
from scripts.password_gen import PasswordGenerator
python
from scripts.password_gen import PasswordGenerator

Generate password

生成密码

gen = PasswordGenerator() password = gen.generate(length=16) print(password) # "K#9mPx$vL2nQ@8wR"
gen = PasswordGenerator() password = gen.generate(length=16) print(password) # "K#9mPx$vL2nQ@8wR"

Generate passphrase

生成密码短语

passphrase = gen.passphrase(words=4) print(passphrase) # "correct-horse-battery-staple"
undefined
passphrase = gen.passphrase(words=4) print(passphrase) # "correct-horse-battery-staple"
undefined

Features

功能特性

  • Secure Generation: Uses cryptographically secure random
  • Custom Rules: Character sets, required types, exclusions
  • Passphrases: Word-based memorable passwords
  • Strength Check: Evaluate password strength
  • Bulk Generation: Generate multiple passwords
  • Pronounceable: Generate easier-to-type passwords
  • 安全生成:使用符合加密标准的随机数生成器
  • 自定义规则:支持字符集、必填字符类型、排除字符等设置
  • 密码短语:基于单词的易记式密码
  • 强度检测:评估密码强度
  • 批量生成:生成多个密码
  • 易读易输:生成便于输入的密码

API Reference

API 参考

Basic Generation

基础生成

python
gen = PasswordGenerator()
python
gen = PasswordGenerator()

Default (16 chars, mixed)

默认设置(16位字符,混合类型)

password = gen.generate()
password = gen.generate()

Custom length

自定义长度

password = gen.generate(length=24)
undefined
password = gen.generate(length=24)
undefined

Character Options

字符选项

python
undefined
python
undefined

Include/exclude character types

包含/排除特定字符类型

password = gen.generate( length=16, uppercase=True, lowercase=True, digits=True, symbols=True )
password = gen.generate( length=16, uppercase=True, lowercase=True, digits=True, symbols=True )

Exclude ambiguous characters (0, O, l, 1, etc.)

排除易混淆字符(0、O、l、1等)

password = gen.generate(length=16, exclude_ambiguous=True)
password = gen.generate(length=16, exclude_ambiguous=True)

Custom character set

自定义字符集

password = gen.generate(length=16, charset="abc123!@#")
password = gen.generate(length=16, charset="abc123!@#")

Exclude specific characters

排除指定字符

password = gen.generate(length=16, exclude="{}[]")
undefined
password = gen.generate(length=16, exclude="{}[]")
undefined

Requirements

规则要求

python
undefined
python
undefined

Require at least N of each type

要求每种字符类型至少包含N个

password = gen.generate( length=16, min_uppercase=2, min_lowercase=2, min_digits=2, min_symbols=2 )
undefined
password = gen.generate( length=16, min_uppercase=2, min_lowercase=2, min_digits=2, min_symbols=2 )
undefined

Passphrases

密码短语

python
undefined
python
undefined

Word-based passphrase

基于单词的密码短语

passphrase = gen.passphrase(words=4)
passphrase = gen.passphrase(words=4)

"correct-horse-battery-staple"

"correct-horse-battery-staple"

Custom separator

自定义分隔符

passphrase = gen.passphrase(words=4, separator="_")
passphrase = gen.passphrase(words=4, separator="_")

"correct_horse_battery_staple"

"correct_horse_battery_staple"

With number

包含数字

passphrase = gen.passphrase(words=3, include_number=True)
passphrase = gen.passphrase(words=3, include_number=True)

"correct-horse-42-battery"

"correct-horse-42-battery"

Capitalize words

单词首字母大写

passphrase = gen.passphrase(words=4, capitalize=True)
passphrase = gen.passphrase(words=4, capitalize=True)

"Correct-Horse-Battery-Staple"

"Correct-Horse-Battery-Staple"

undefined
undefined

Strength Check

强度检测

python
strength = gen.check_strength("MyP@ssw0rd!")
python
strength = gen.check_strength("MyP@ssw0rd!")

{

{

'score': 3, # 0-4 scale

'score': 3, # 0-4分制

'label': 'Strong', # Weak, Fair, Good, Strong, Very Strong

'label': 'Strong', # Weak、Fair、Good、Strong、Very Strong

'entropy': 65.2, # Bits of entropy

'entropy': 65.2, # 熵值(比特)

'feedback': ['Good length', 'Has symbols']

'feedback': ['Good length', 'Has symbols']

}

}

undefined
undefined

Bulk Generation

批量生成

python
undefined
python
undefined

Generate multiple passwords

生成多个密码

passwords = gen.generate_bulk(count=10, length=16)
passwords = gen.generate_bulk(count=10, length=16)

To CSV

导出为CSV

gen.generate_to_csv("passwords.csv", count=100, length=20)
undefined
gen.generate_to_csv("passwords.csv", count=100, length=20)
undefined

CLI Usage

CLI 用法

bash
undefined
bash
undefined

Generate single password

生成单个密码

python password_gen.py --length 16
python password_gen.py --length 16

Generate passphrase

生成密码短语

python password_gen.py --passphrase --words 4
python password_gen.py --passphrase --words 4

Custom options

自定义选项

python password_gen.py --length 20 --no-symbols --exclude-ambiguous
python password_gen.py --length 20 --no-symbols --exclude-ambiguous

Bulk generate

批量生成

python password_gen.py --count 10 --length 16
python password_gen.py --count 10 --length 16

Check strength

检测强度

python password_gen.py --check "MyPassword123!"
python password_gen.py --check "MyPassword123!"

Generate to file

生成到文件

python password_gen.py --count 100 --output passwords.txt
undefined
python password_gen.py --count 100 --output passwords.txt
undefined

CLI Arguments

CLI 参数

ArgumentDescriptionDefault
--length
Password length16
--count
Number to generate1
--passphrase
Generate passphraseFalse
--words
Words in passphrase4
--no-uppercase
Exclude uppercaseFalse
--no-lowercase
Exclude lowercaseFalse
--no-digits
Exclude digitsFalse
--no-symbols
Exclude symbolsFalse
--exclude-ambiguous
Exclude 0, O, l, 1False
--check
Check password strength-
--output
Output file-
参数描述默认值
--length
密码长度16
--count
生成数量1
--passphrase
生成密码短语False
--words
密码短语的单词数量4
--no-uppercase
排除大写字母False
--no-lowercase
排除小写字母False
--no-digits
排除数字False
--no-symbols
排除符号False
--exclude-ambiguous
排除易混淆字符False
--check
检测密码强度-
--output
输出文件路径-

Examples

示例

Strong Random Password

高强度随机密码

python
gen = PasswordGenerator()
password = gen.generate(
    length=20,
    min_uppercase=2,
    min_lowercase=2,
    min_digits=2,
    min_symbols=2
)
print(f"Password: {password}")
print(f"Strength: {gen.check_strength(password)['label']}")
python
gen = PasswordGenerator()
password = gen.generate(
    length=20,
    min_uppercase=2,
    min_lowercase=2,
    min_digits=2,
    min_symbols=2
)
print(f"Password: {password}")
print(f"Strength: {gen.check_strength(password)['label']}")

Memorable Passphrase

易记密码短语

python
gen = PasswordGenerator()
passphrase = gen.passphrase(
    words=4,
    capitalize=True,
    include_number=True,
    separator="-"
)
print(passphrase)
python
gen = PasswordGenerator()
passphrase = gen.passphrase(
    words=4,
    capitalize=True,
    include_number=True,
    separator="-"
)
print(passphrase)

"Tiger-Mountain-42-Sunset-Lake"

"Tiger-Mountain-42-Sunset-Lake"

undefined
undefined

PIN Generation

PIN码生成

python
gen = PasswordGenerator()
pin = gen.generate(
    length=6,
    uppercase=False,
    lowercase=False,
    digits=True,
    symbols=False
)
print(f"PIN: {pin}")  # "847291"
python
gen = PasswordGenerator()
pin = gen.generate(
    length=6,
    uppercase=False,
    lowercase=False,
    digits=True,
    symbols=False
)
print(f"PIN: {pin}")  # "847291"

Batch for Team

团队批量生成

python
gen = PasswordGenerator()
python
gen = PasswordGenerator()

Generate passwords for new team members

为新团队成员生成密码

team = ["alice", "bob", "charlie"] for member in team: password = gen.generate(length=16) print(f"{member}: {password}")
undefined
team = ["alice", "bob", "charlie"] for member in team: password = gen.generate(length=16) print(f"{member}: {password}")
undefined

Strength Scoring

强度评分标准

ScoreLabelDescription
0Very Weak< 28 bits entropy
1Weak28-35 bits
2Fair36-59 bits
3Strong60-127 bits
4Very Strong128+ bits
分数等级描述
0极弱熵值 < 28比特
128-35比特
2一般36-59比特
360-127比特
4极强128+比特

Dependencies

依赖项

(No external dependencies - uses Python standard library)
(无外部依赖 - 仅使用Python标准库)

Security Notes

安全说明

  • Uses
    secrets
    module for cryptographic randomness
  • Never logs or stores generated passwords
  • Passphrase wordlist is embedded (no external calls)
  • Strength check is local (no external API)
  • 使用
    secrets
    模块实现加密级随机数生成
  • 绝不会记录或存储生成的密码
  • 密码短语词库内置(无外部调用)
  • 强度检测本地完成(无外部API调用)