【发布时间】:2018-11-09 01:48:17
【问题描述】:
我正在尝试创建一个用户登录系统程序。我正在尝试确保密码必须至少包含 10 个字符,但我无法确保它至少包含两个数字并且仅下划线作为特殊字符。我见过一些关于数字的解决方案,但我没有得到它们,而且它们很少有至少 2 位数字。
这是我的代码:
print("Welcome ")
print('')
print('New users should enter Sign to create an account')
print('')
print('')
username = input('Enter your Username: ')
if username == 'Sign':
while True:
usernames = ['Dave','Alice','Chloe']#A list that stores usernames
create_user = input('Enter your new username: ')
if create_user in usernames:
print('This user name has been taken .Try again')
continue
else:
break
usernames.append([create_user])
while True:
create_pass = input('Enter your your user password: ')
passwords = []#A list thst stores password
pass_len = len(create_pass)
if pass_len < 10:
print('Your password must be at least 10. Try again')
continue
else:
print('')
print('You are now a verified user.')
print('Run the application again to re-login.')
print('Thank You')
break
else:
password = input('Enter your password')
print('Visit www.bitly/p8?. to continue')
【问题讨论】:
-
要求特殊字符是好的。限制允许使用哪些特殊字符是不好的,而且通常是不必要的。您对允许集的约束越多,暴力破解密码所需的工作就越少。
标签: python