2 : 주말 작업을 통합 :
2.1 : 쓰기 사용자 인터페이스 로그인
(1)의 채택 후 검증, 검증 출력 "로그인 성공"을 완료하려면 계정 암호를 입력
inp_name = input('输入账号: ').strip()
inp_pwd = input('输入密码: ').strip()
if inp_name == 'tom' and inp_pwd == '111':
print('登录成功')
else:
print('账号或密码不正确')
2, 다른 사용자가 로그인 할 수 있습니다
user_info = {'tom': '111', 'jack': '222', 'marry': '333'}
inp_name = input('输入账号: ').strip()
inp_pwd = input('输入密码: ').strip()
if inp_name in user_info and inp_pwd == user_info[inp_name]:
print('登录成功')
else:
print('账号或密码不正确')
같은 계정을 입력하기 위해 3, 실패한 시도가 잠겨 (참고 : 파일에 사용자를 잠금 그래서 프로그램을 보장하는 폐쇄 될 때, 사용자는 여전히 잠겨)
all_user_info = {
'tom': 111,
'jarry': 222,
'jack': 333
}
tage = True
number = 0
while tage:
username = input('请输入用户名: ')
if username in all_user_info:
print('当前用户为:{}'.format(username))
with open('a.txt', mode='rt', encoding='utf_8') as f1:
res = f1.read()
x = res.split()
if username in x:
print('当前用户也被锁定')
else:
while number < 3:
password = input('输入密码: ')
if password == all_user_info.get(username):
pirnt('登录成功')
tage = False
break
else:
print('密码输入错误!')
number += 1
if number == 3:
number = 0
print('当前用户输错三次已被锁定')
with open('a.txt', mode='at', encoding='utf_8') as f1:
f1.write('{}:'.format(username))
break
else:
print('用户不存在')
2.2 : 프로그래밍 사용자 등록을 실행 한 후 로그인 할 수 있습니다
1,
tage = True
while tage:
msg = """
0 退出
1 登录
2 注册
"""
print(msg)
cmd = input('请输入命令编号>>: ').strip()
if not cmd.isdigit():
print('必须输入命令编号的数字,傻叉')
continue
if cmd == '0':
break
elif cmd == '1':
with open('a.txt', mode='rt', encoding='utf_8') as f1:
for i in range(3):
inp_name = input('输入账号: ').strip()
inp_password = input('输入密码: ').strip()
for line in f1:
username, password = line.strip().split(':')
if inp_name == username and inp_password == password:
print('登录成功')
tage = False
break
break
else:
print('输错三次,退出')
tage = False
elif cmd == '2':
with open('a.txt', mode='at', encoding='utf_8') as f2:
inp_name = input('输入账号: ').strip()
inp_password = input('输入密码: ').strip()
f2.write('{}:{}\n'.format(inp_name, inp_password))
else:
print('输入的命令不存在')
2,
2 : 주말 작업을 통합 :
2.1 : 쓰기 사용자 인터페이스 로그인
(1)의 채택 후 검증, 검증 출력 "로그인 성공"을 완료하려면 계정 암호를 입력
inp_name = input('输入账号: ').strip()
inp_pwd = input('输入密码: ').strip()
if inp_name == 'tom' and inp_pwd == '111':
print('登录成功')
else:
print('账号或密码不正确')
2, 다른 사용자가 로그인 할 수 있습니다
user_info = {'tom': '111', 'jack': '222', 'marry': '333'}
inp_name = input('输入账号: ').strip()
inp_pwd = input('输入密码: ').strip()
if inp_name in user_info and inp_pwd == user_info[inp_name]:
print('登录成功')
else:
print('账号或密码不正确')
같은 계정을 입력하기 위해 3, 실패한 시도가 잠겨 (참고 : 파일에 사용자를 잠금 그래서 프로그램을 보장하는 폐쇄 될 때, 사용자는 여전히 잠겨)
all_user_info = {
'tom': 111,
'jarry': 222,
'jack': 333
}
tage = True
number = 0
while tage:
username = input('请输入用户名: ')
if username in all_user_info:
print('当前用户为:{}'.format(username))
with open('a.txt', mode='rt', encoding='utf_8') as f1:
res = f1.read()
x = res.split()
if username in x:
print('当前用户也被锁定')
else:
while number < 3:
password = input('输入密码: ')
if password == all_user_info.get(username):
pirnt('登录成功')
tage = False
break
else:
print('密码输入错误!')
number += 1
if number == 3:
number = 0
print('当前用户输错三次已被锁定')
with open('a.txt', mode='at', encoding='utf_8') as f1:
f1.write('{}:'.format(username))
break
else:
print('用户不存在')
2.2 : 프로그래밍 사용자 등록을 실행 한 후 로그인 할 수 있습니다
1,
tage = True
while tage:
msg = """
0 退出
1 登录
2 注册
"""
print(msg)
cmd = input('请输入命令编号>>: ').strip()
if not cmd.isdigit():
print('必须输入命令编号的数字,傻叉')
continue
if cmd == '0':
break
elif cmd == '1':
with open('a.txt', mode='rt', encoding='utf_8') as f1:
for i in range(3):
inp_name = input('输入账号: ').strip()
inp_password = input('输入密码: ').strip()
for line in f1:
username, password = line.strip().split(':')
if inp_name == username and inp_password == password:
print('登录成功')
tage = False
break
break
else:
print('输错三次,退出')
tage = False
elif cmd == '2':
with open('a.txt', mode='at', encoding='utf_8') as f2:
inp_name = input('输入账号: ').strip()
inp_password = input('输入密码: ').strip()
f2.write('{}:{}\n'.format(inp_name, inp_password))
else:
print('输入的命令不存在')
2,