怎么用Python检验用户输入密码的复杂度
作者:Jason
时间:2023-04-25
浏览:3
密码强度检测规则:至少包含一个数字至少包含一个大写字母长度至少8位主要知识点while循环推导式列表any函数命令行input代码部分密码强度检测1、首先创建一个python文件导入系统包importplatform密码强度检测规则至少包含一个数字至少包含一个大写字母长度至少8位每天打印一词,激励一下自己。print("人生苦短,我用Python")输入密码whileTrue:password=input("请输入待检测密码:")列表推导式使用print("数字检测:",[i.isdigit()forii
本文目录
密码强度检测规则:
至少包含一个数字
至少包含一个大写字母
长度至少 8 位
主要知识点
while 循环
推导式
列表 any 函数
命令行 input
代码部分
密码强度检测
1、首先创建一个 python 文件
导入系统包
import platform
密码强度检测规则
至少包含一个数字至少包含一个大写字母长度至少 8 位
每天打印一词,激励一下自己。
print("人生苦短,我用Python")输入密码
while True:
password = input("请输入待检测密码: ")列表推导式使用
print("数字检测: ", [i.isdigit() for i in password])
print("大写字母检测: ", [i.isupper() for i in password])
print("密码长度: ", len(password))是否有数字, 推导式检测。
hasNumber = any([i.isdigit() for i in password])
是否有大写字母, 推导式检测。
hasUpper = any([i.isupper() for i in password])
密码检测
if hasNumber and hasUpper and len(password) >= 8:
print("密码符合规则, 检查通过")
break
else:
print("密码校验未通过, 请重新输入")2、运行结果
请输入待检测密码: 123213 数字检测: [True, True, True, True, True, True] 大写字母检测: [False, False, False, False, False, False] 密码长度: 6 密码校验未通过, 请重新输入 请输入待检测密码: abc1234 数字检测: [False, False, False, True, True, True, True] 大写字母检测: [False, False, False, False, False, False, False] 密码长度: 7 密码校验未通过, 请重新输入 请输入待检测密码: Abc34567 数字检测: [False, False, False, True, True, True, True, True] 大写字母检测: [True, False, False, False, False, False, False, False] 密码长度: 8 密码符合规则, 检查通过
全部代码
import platform
print("人生苦短,我用Python")
while True:
password = input("请输入待检测密码: ")
print("数字检测: ", [i.isdigit() for i in password])
print("大写字母检测: ", [i.isupper() for i in password])
print("密码长度: ", len(password))
hasNumber = any([i.isdigit() for i in password])
hasUpper = any([i.isupper() for i in password])
if hasNumber and hasUpper and len(password) >= 8:
print("密码符合规则, 检查通过")
break
else:
print("密码校验未通过, 请重新输入")
作者最新文章
blender添加灯光快捷键是什么及使用方法教程
2026-10-14 13:52
漫蛙漫画在线观看入口
2026-10-13 13:46
Microsoft365商业版怎么用Word多人一起改文档
2026-10-05 15:20
photoshop工具导出文件缓存怎么删除
2026-10-04 11:51
如何卸载python:环境隔离、依赖清理与验证流程的避坑指南
2026-09-05 11:31
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多










































