【发布时间】:2019-03-23 16:31:04
【问题描述】:
...其中密码必须满足以下条件:
- 超过 8 个字符
- 至少1个大写字母和1个小写字母、1个数字和1个特殊符号
- 不包含用户名
def enterUsername():
username = input("Enter username: ")
username = enterUsername()
def enterPassword():
LENGTH = 8
password = input("Enter password: ")
upCase = False #indicate if password has at least 1 upper
lowCase = False #indicate if password has at least 1 lower
digit = False #indicate if password has at least 1 digit
special = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '_', '=']
for char in password: #iterate on each character of password (go through every character, for each character in the string)
if char.isupper(): #if character is in upper, set upCase to
upCase = True
if char.islower(): #if character is in lower, set lowCase to
lowCase = True
if char.isdigit(): #if character is a digit, set digit to
digit = True
for spechar in special:
if char == spechar:
special = True
length = len(password) #get length of password
strong = upCase and lowCase and digit and special and length > LENGTH #strong would be true if all the conditions hold
while True:
password = input("Enter password: ")
if not strong:
print("Your password is weak.")
else:
print ("Your password is strong enough.")
break
return password
enterPassword()
【问题讨论】:
-
欢迎来到stackoverflow。请找出您的代码存在的问题。
标签: python python-3.x