Python编写密码验证程序
时间: 2023-11-05 21:25:43 浏览: 59
好的,我可以给你提供一个简单的Python程序,用于密码验证:
```python
password = input("请输入要验证的密码:")
# 判断密码长度是否符合要求
if len(password) < 8 or len(password) > 16:
print("密码长度应在8-16位之间")
else:
# 判断密码是否包含大小写字母、数字和符号
has_upper = False
has_lower = False
has_digit = False
has_symbol = False
for ch in password:
if ch.isupper():
has_upper = True
elif ch.islower():
has_lower = True
elif ch.isdigit():
has_digit = True
else:
has_symbol = True
if has_upper and has_lower and has_digit and has_symbol:
print("密码验证通过")
else:
print("密码应包含大小写字母、数字和符号")
```
这个程序会要求用户输入一个密码,然后判断密码是否符合要求。如果密码长度在8-16位之间,并且包含大小写字母、数字和符号,就会输出“密码验证通过”。否则,会输出相应的错误提示。