Python 密码强度验证代码示例
接收用户输入的密码
password = input('请输入密码:')
检查密码长度是否合法
if len(password) < 6 or len(password) > 12: print('密码长度应为6-12位')
检查密码中是否包含数字
elif not any(char.isdigit() for char in password): print('密码中至少应包含1个数字')
检查密码中是否包含小写字母
elif not any(char.islower() for char in password): print('密码中至少应包含1个小写字母')
检查密码中是否包含大写字母
elif not any(char.isupper() for char in password): print('密码中至少应包含1个大写字母')
如果以上条件都满足,则密码合法
else: print('密码符合要求')
原文地址: https://www.cveoy.top/t/topic/ohxF 著作权归作者所有。请勿转载和采集!