生成受XKCD启发的安全多词密码/密码短语
项目描述
xkcdpass
xkcdpass是一个灵活且可脚本化的密码生成器,可生成强大的密码短语,受XKCD 936启发
$ xkcdpass > correct horse battery staple
安装
xkcdpass可以使用pip轻松安装
pip install xkcdpass
或手动安装
python setup.py install
源代码
最新开发版本可以在github上找到:https://github.com/redacted/XKCD-password-generator
欢迎并感谢贡献!
要求
Python 2(版本2.7或更高),或Python 3(版本3.4或更高)。在Python 2上运行模块单元测试需要安装mock。
运行 xkcdpass
xkcdpass可以不带任何参数调用
$ xkcdpass > pinball previous deprive militancy bereaved numeric
它将返回一个密码,使用默认的字典和默认设置。或者您可以混合您想要的任何参数
$ xkcdpass --count=5 --acrostic='chaos' --delimiter='|' --min=5 --max=6 --valid-chars='[a-z]' > collar|highly|asset|ovoid|sultan > caper|hangup|addle|oboist|scroll > couple|honcho|abbot|obtain|simple > cutler|hotly|aortae|outset|stool > cradle|helot|axial|ordure|shale
它将返回
--count=5 5个可供选择的密码
--acrostic='chaos' 其首字母拼出'chaos'
--delimiter='|' 使用'|'连接
--min=5 --max=6 单词长度在5到6个字符之间
--valid-chars='[a-z]' 仅使用小写字母(通过正则表达式)。
可以通过以下方式访问可用的 xkcdpass 选项的简要概述:
xkcdpass --help Usage: xkcdpass [options] Options: -h, --help show this help message and exit -w WORDFILE, --wordfile=WORDFILE Specify that the file WORDFILE contains the list of valid words from which to generate passphrases. Multiple wordfiles can be provided, separated by commas. Provided wordfiles: eff-long (default), eff-short, eff-special, legacy, spa-mich (Spanish), fin-kotus (Finnish) ita-wiki (Italian), ger-anlx (German), nor-nb (Norwegian), fr-freelang (French), pt-ipublicis / pt-l33t-ipublicis (Portuguese) swe-short (Swedish) --min=MIN_LENGTH Minimum length of words to make password --max=MAX_LENGTH Maximum length of words to make password -n NUMWORDS, --numwords=NUMWORDS Number of words to make password -i, --interactive Interactively select a password -v VALID_CHARS, --valid-chars=VALID_CHARS Valid chars, using regexp style (e.g. '[a-z]') -V, --verbose Report various metrics for given options, including word list entropy -a ACROSTIC, --acrostic=ACROSTIC Acrostic to constrain word choices -c COUNT, --count=COUNT number of passwords to generate -d DELIM, --delimiter=DELIM separator character between words -R, --random-delimiters use randomised delimiters -D DELIMITERS, --valid-delimiters=DELIMETERS delimeters to choose from, used with - -s SEP, --separator SEP Separate generated passphrases with SEP. -C CASE, --case CASE Choose the method for setting the case of each word in the passphrase. Choices: ['alternating', 'upper', 'lower', 'random', 'capitalize', 'as-is'] (default: 'lower'). --allow-weak-rng Allow fallback to weak RNG if the system does not support cryptographically secure RNG. Only use this if you know what you are doing.
单词列表
该软件包提供了几个单词列表。默认的 eff-long 由电子前沿基金会(EFF)专门设计用于 生成密码短语,并受 CC BY 3.0 许可。由于它最初是用于与 Diceware 一起使用,因此在使用时请确保您的密码短语中至少有六个单词。该列表的两个较短变体,eff-short 和 eff-special,也已包括在内。有关更多信息,请参阅上面的 EFF 文档。
此外,还提供了 xkcdpass 1.10.0 之前版本的原始单词列表,作为便利选项,可在 legacy 下找到。此单词列表是通过 Alan Beale 的 12Dicts 机械生成的。据 xkcdpass 的作者了解,纯粹机械的转换并不在结果作品中赋予版权。在 http://wordlist.aspell.net/12dicts/ 的 12Dicts 项目文档中包含以下献词:
12dicts 列表由 Alan Beale 编制。我明确将其释放到公共领域,但要求承认其使用。
请注意,生成器可以与任何正确格式的单词文件一起使用:每行一个“单词”的文件。
附加语言
西班牙语:这是 archive.umich.edu 中 /linguistics 目录的一个修改版本。它包括约 80,000 个单词。已使用正则表达式删除了少于 5 个字符和类似拉丁字母的单词。此列表是公共领域,请参阅 此处。
芬兰语:这是芬兰语言研究所 XML 单词列表的一个修改版本。已使用正则表达式删除了淫秽和包含空格的表达式。生成的列表包含约 93,000 个单词。此列表根据 GNU LGPL、EUPL 1.1 和 CC-BY 3.0 许可证发布。
意大利语:从意大利语维基百科的存档生成的。
德语(ger-anlx):基于 此 GPL v3 列表。删除了单字符和双字符单词。
德语(eff_large_de_sample.wordlist):基于 此公共领域词典。转换为 UTF-8 并随机采样以减小文件大小。
挪威语:这是 Norsk Ordbank 在挪威语 Bokmål 2005 的一个修改版本,2018 年 6 月 28 日更新,该版本受 CC-BY 4.0 许可证发布。已使用正则表达式修改列表以进行清理和删除不切实际的单词。生成的列表包含约 137,000 个单词。
法语:这是 此列表(公共领域)的一个清洁版本,以及一个过滤版本,以删除可能令人反感的单词。
葡萄牙语:这是 LibreOffice / Firefox 葡萄牙语词典的转换版本(来自 此链接)。受 GPL 和 BSD 许可证许可。
瑞典语:这是 Martin Lindhe 的瑞典语单词列表的一个修改版本(MIT 许可证)。修改也以 MIT 许可证发布。
始终欢迎提供附加语言的单词列表!
将 xkcdpass 作为导入模块使用
xkcdpass 的内置功能可以通过将其导入 Python 脚本进行扩展。在 example_import.py 中提供了一个使用示例,该示例随机将生成的密码中的字母转换为大写。另外,example_json.py 展示了将 xkcdpass 集成到 Django 项目中的方法,以 JSON 格式生成密码建议,供 JavaScript 前端使用。
导入示例
from xkcdpass import xkcd_password as xp # create a wordlist from the default wordfile # use words between 5 and 8 letters long wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8) # create a password with the acrostic "face" print(xp.generate_xkcdpassword(mywords, acrostic="face"))
当作为导入模块使用时,generate_wordlist() 函数接收以下参数(显示默认值)
wordfile=None, min_length=5, max_length=9, valid_chars='.'
而 generate_xkcdpassword() 函数接收
wordlist, numwords=6, interactive=False, acrostic=False, delimiter=" "
不安全的随机数生成器
xkcdpass 尽可能使用密码学上安全的随机数生成器(由 random.SystemRandom() 在大多数现代操作系统上提供)。从版本 1.7.0 开始,必须明确启用回退到不安全的 RNG,可以通过在运行脚本之前使用新的命令行变量,或者设置相应的环境变量来实现。
xkcdpass --allow-weak-rng
export XKCDPASS_ALLOW_WEAKRNG=1
变更日志
1.19.9 在测试中删除了对已弃用的 assertEquals 的使用
1.19.8 启用 python -m xkcdpass 使用
1.19.7 添加瑞典单词列表,改进测试套件,改进 setup.py(安装时排除示例)
1.19.6 修复随机失败的单元测试
1.19.5 添加“as-is”选项用于大小写
1.19.4 使随机分隔符行为与固定分隔符一致
1.19.3 恢复 eff_large_de 单词列表的随机采样版本
1.19.2 减少安装大小
1.19.1 改进帮助文本,处理参数导致空单词列表的罕见情况
1.19.0 首次支持多个单词文件
1.18.2 修复 README
1.18.0 添加随机分隔符
1.17.6 修复错误
1.17.5 修复错误
1.17.4 改进法语字典
1.17.3 更新许可协议和支持版本
1.17.2 修复 2.x/3.x 兼容性问题
1.17.1 修复 README 和 Unicode 编码问题
1.17.0 添加法语、挪威语和葡萄牙语字典。修复错误并改进测试(WIP)。
许可证
这是一个免费软件:您可以在 BSD 3-Clause 许可证的条款下复制、修改和/或分发此作品。有关详细信息,请参阅文件 LICENSE.BSD。