本文目录导读:

核心Python脚本(推荐)
#!/usr/bin/env python3
import secrets
import string
import argparse
import sys
def generate_password(length=16, use_digits=True, use_punctuation=True):
"""生成安全的随机密码"""
# 基础字符集:大小写字母
chars = string.ascii_letters
if use_digits:
chars += string.digits
if use_punctuation:
chars += string.punctuation
if len(chars) < 4: # 安全检查
print("错误:字符集过小", file=sys.stderr)
sys.exit(1)
# 使用secrets模块保证密码安全性(适合密码学应用)
password = ''.join(secrets.choice(chars) for _ in range(length))
return password
def main():
parser = argparse.ArgumentParser(description='生成随机密码')
parser.add_argument('-l', '--length', type=int, default=16, help='密码长度 (默认: 16)')
parser.add_argument('-nd', '--no-digits', action='store_true', help='排除数字')
parser.add_argument('-np', '--no-punctuation', action='store_true', help='排除特殊字符')
args = parser.parse_args()
if args.length < 8:
print("警告:建议密码长度至少8位", file=sys.stderr)
password = generate_password(
length=args.length,
use_digits=not args.no_digits,
use_punctuation=not args.no_punctuation
)
print(password)
if __name__ == "__main__":
main()
使用示例:
# 生成16位密码(含数字和特殊字符) python passgen.py # 生成32位纯字母密码 python passgen.py -l 32 -nd -np # 生成20位密码(仅含字母和数字) python passgen.py -l 20 -np
单行命令(快速使用)
Linux/macOS(使用openssl):
# 16位密码,包含各类字符 openssl rand -base64 12 | tr -d '\n' | head -c 16 && echo # 更安全的版本(urandom) cat /dev/urandom | tr -dc 'a-zA-Z0-9!@#$%^&*()_+' | head -c 16 && echo
Windows PowerShell:
# 生成16位密码
-join ((48..57) + (65..90) + (97..122) + (33..47) | Get-Random -Count 16 | % {[char]$_})
增强版脚本(带密码强度检查)
#!/usr/bin/env python3
import secrets
import string
import re
def create_strong_password(length=20):
"""生成符合常见密码策略的强密码"""
# 至少包含每个类别的一个字符
all_chars = string.ascii_letters + string.digits + string.punctuation
# 先确保包含各类字符
password = [
secrets.choice(string.ascii_lowercase),
secrets.choice(string.ascii_uppercase),
secrets.choice(string.digits),
secrets.choice(string.punctuation)
]
# 填充剩余长度
password += [secrets.choice(all_chars) for _ in range(length - 4)]
# 随机打乱顺序
secrets.SystemRandom().shuffle(password)
return ''.join(password)
def password_strength(password):
"""评估密码强度(返回0-100分数)"""
score = 0
if len(password) >= 12: score += 20
if len(password) >= 16: score += 10
if re.search(r'[a-z]', password): score += 15
if re.search(r'[A-Z]', password): score += 15
if re.search(r'\d', password): score += 20
if re.search(r'[!@#$%^&*(),.?":{}|<>]', password): score += 20
return score
# 使用示例
pwd = create_strong_password(24)
print(f"生成的密码: {pwd}")
print(f"密码强度: {password_strength(pwd)}/100")
批量生成密码(输出到文件)
#!/bin/bash
# 批量生成多个密码到文件
COUNT=10
LENGTH=20
for i in $(seq 1 $COUNT); do
openssl rand -base64 20 | tr -d '/+=' | cut -c1-$LENGTH
done > passwords.txt
echo "已生成 $COUNT 个密码,保存到 passwords.txt"
安全建议
- 使用专业的密码管理器(如LastPass, Bitwarden)管理生成的密码
- 密码长度应至少12位,推荐16-20位
- 避免使用常见模式(如password123, admin2024等)
- 不同网站使用不同密码,不要重复使用
- 启用多因素认证(2FA/MFA)作为额外保护
这些脚本可以满足日常开发、服务器配置、临时账户创建等场景的需求,记得根据实际需求调整密码长度和字符集。
版权声明:NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播