valorisa/Password-Generator-Advanced

GitHub: valorisa/Password-Generator-Advanced

一款基于 Python secrets 模块的命令行安全密码与 passphrase 生成器,支持严格密码学约束、批量生成及熵值评估。

Stars: 1 | Forks: 0

# Password-Generator-Advanced [![CI](https://static.pigsec.cn/wp-content/uploads/repos/cas/ad/ad5834178f7599af9fdda11629d49cae07f2997beec49821b2920eff5bfd50e7.svg)](https://github.com/valorisa/Password-Generator-Advanced/actions/workflows/ci.yml) [![PyPI version](https://img.shields.io/pypi/v/Password-Generator-Advanced.svg)](https://pypi.org/project/Password-Generator-Advanced/) ![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg) ![Python 3.12+](https://img.shields.io/badge/Python-3.12%2B-3776AB.svg?logo=python&logoColor=white) ![Security: secrets](https://img.shields.io/badge/Security-secrets%20module-green.svg) 一款具有严格密码学限制的命令行安全密码生成器。每个生成的密码都必须包含小写字母、大写字母、数字和特殊字符,并具有可配置的最少数量限制。 ## 快速安装 **Password-Generator-Advanced 已在 PyPI 上发布!** 任何人都可以直接使用 pip 安装: ``` pip install Password-Generator-Advanced ``` 安装完成后,只需运行: ``` password-generator-advanced ``` 该包兼容 **Python 3.12+**,并可在 Linux、macOS 和 Windows 上运行。 **这条命令会做什么?** - 自动从 PyPI 下载最新稳定版本 - 将该包安装到您的 Python 环境中 - 使 `password-generator-advanced` 命令全局可用 **更新到最新版本:** ``` pip install --upgrade Password-Generator-Advanced ``` **在虚拟环境中安装(推荐):** ``` # 创建虚拟环境 python -m venv venv # 激活环境 # 在 Linux/macOS 上: source venv/bin/activate # 在 Windows 上: venv\Scripts\activate # 安装 package pip install Password-Generator-Advanced ``` ### 替代方案:从源码安装 如果您希望为项目做出贡献或使用开发版本: ``` git clone https://github.com/valorisa/Password-Generator-Advanced.git cd Password-Generator-Advanced poetry install ``` **从源码安装的前提条件:** - Python 3.12 或更高版本 - Poetry(依赖管理工具) ## 功能 - 带有严格限制(可配置)的密码生成 - 生成 passphrase(Diceware 风格,2048 个单词,每个单词 11 位熵) - 评估现有密码或 passphrase 的强度 - 复制到剪贴板(Windows、macOS、Linux) - 交互模式(菜单)和 CLI 模式(命令行参数) ## 默认限制 | 限制 | 保证的最少数量 | |------------|-----------------| | 数字 (0-9) | 9 | | 特殊字符 (`!@#$%^&*`...) | 9 | | 小写字母 (a-z) | 1 | | 大写字母 (A-Z) | 1 | | **最小总长度** | **20 个字符** | 数字和特殊字符的限制可以通过 `--min-digits` 和 `--min-special` 进行配置。 使用 Python `secrets` 模块进行生成(CSPRNG — 密码学安全的伪随机数生成器)。 ## 用法 ### 交互模式 **如果您是通过 PyPI 使用 pip 安装的:** ``` password-generator-advanced ``` **如果您是从源码安装的(使用 Poetry):** ``` python -m password_generator_advanced ``` *注意:这两条命令是等效的,都会启动同一个程序。* 将显示交互式菜单: ``` ================================================== GÉNÉRATEUR DE MOTS DE PASSE SÉCURISÉS ================================================== Contraintes appliquées : - Minimum 9 chiffres - Minimum 9 caractères spéciaux - Au moins 1 lettre minuscule - Au moins 1 lettre majuscule - Longueur minimale : 20 caractères -------------------------------------------------- 1 - Générer un mot de passe 2 - Générer plusieurs mots de passe 3 - Générer une passphrase 4 - Évaluer un mot de passe / passphrase 5 - Quitter -------------------------------------------------- ``` ### CLI 模式 ``` # 生成密码(长度为 30) python -m password_generator_advanced --length 30 # 生成 5 个密码 python -m password_generator_advanced --length 25 --count 5 # 自定义约束 python -m password_generator_advanced --length 20 --min-digits 3 --min-special 5 # 生成 passphrase(默认 6 个单词) python -m password_generator_advanced --passphrase # 带选项的 passphrase python -m password_generator_advanced --passphrase --words 8 --separator "." # 评估现有密码 python -m password_generator_advanced --evaluate "mon-super-mot-de-passe!" # 将结果复制到剪贴板 python -m password_generator_advanced --length 25 --copy ``` ### 完整的 CLI 选项 | 选项 | 简写 | 描述 | |--------|-------|-------------| | `--length` | `-l` | 密码长度 | | `--min-digits` | | 最少数字个数(默认:9) | | `--min-special` | | 最少特殊字符个数(默认:9) | | `--count` | `-n` | 要生成的密码数量 | | `--passphrase` | `-p` | 生成 passphrase | | `--words` | `-w` | passphrase 的单词数量(默认:6) | | `--separator` | | passphrase 的分隔符(默认:`-`) | | `--evaluate` | `-e` | 评估密码的理论熵 | | `--copy` | `-c` | 复制到剪贴板 | ## 密码评估 该工具可以评估现有密码或 passphrase 的最大理论熵: ``` Entropie théorique maximale : Longueur : 28 caractères Entropie max. : 164.0 bits Niveau : Très fort Jeu de caractères: 58 symboles possibles Catégories détectées : Minuscules : ✓ Majuscules : ✗ Chiffres : ✗ Spéciaux : ✓ ⚠ Ce calcul suppose un choix aléatoire par caractère. Un mot de passe basé sur des mots du dictionnaire ou des patterns prévisibles aura une entropie réelle inférieure. ``` 阈值(与 ANSSI 的建议保持一致): | 熵 | 等级 | |----------|--------| | < 48 位 | 非常弱 | | 48-63 位 | 弱 | | 64-79 位 | 中等 | | 80-127 位 | 强 | | ≥ 128 位 | 非常强 | ## 项目架构 ``` Password-Generator-Advanced/ ├── src/ │ └── password_generator_advanced/ │ ├── __init__.py # Version du package │ ├── __main__.py # Point d'entrée python -m │ ├── main.py # Menu interactif + CLI argparse │ ├── generator.py # Algorithme de génération + évaluation │ ├── wordlist.py # Liste de 2048 mots pour passphrases │ └── clipboard.py # Copie presse-papier cross-platform ├── tests/ │ └── test_generator.py # 18 tests ├── pyproject.toml # Configuration Poetry ├── LICENSE # MIT ├── SECURITY.md ├── CONTRIBUTING.md └── CODE_OF_CONDUCT.md ``` ### 生成算法 (`generator.py`) 1. **保证位置**:首先放置 N 个数字 + N 个特殊字符 + 1 个小写字母 + 1 个大写字母 2. **填充**:使用所有类别的随机混合填充剩余位置 3. **最终打乱**:通过 `secrets.SystemRandom().shuffle()` 打乱整体,以消除任何可预测的位置模式 ### 生成 passphrase 从包含 2048 个单词的列表中随机选择单词(每个单词提供 11 位熵)。一个 6 个单词的 passphrase 可提供约 66 位熵。 ## 安全性 - **`secrets` 模块**:使用操作系统的密码学安全随机生成器(Linux/macOS 上的 `/dev/urandom`,Windows 上的 `CryptGenRandom`) - **无外部依赖**:仅使用 Python 标准库 —— 没有第三方的攻击面 - **不进行存储**:生成的密码永远不会写入磁盘,也不会通过网络发送 如需报告漏洞,请参阅 [SECURITY.md](SECURITY.md)。 ## 开发 ``` # 运行测试 poetry run pytest tests/ -v # 检查 style poetry run ruff check . # 自动修复 poetry run ruff check . --fix ``` ## 许可证 [MIT](LICENSE) - 允许自由使用、商业使用和修改。 **作者**:[valorisa](https://github.com/valorisa)
标签:CSPRNG, Python, 安全规则引擎, 密码学, 密码生成器, 手动系统调用, 无后门, 逆向工具