Author: Zeno
date:2024/4/16
time:11:51
【1】注册 :
(1)存储到文件中
(2)存储数据格式:用户名 - 登录密码 - 年龄 - 银行卡号(1314) - 取款密码 - 余额(1000) 默认余额 1000
(3)校验用户名存在不允许注册
(4)校验密码,必须是 6 位 ,并且字母和数据混合 ---> 提高数据的安全等级
(5)取款密码,必须是数字且 是三位
【2】登录 :
(1)直接将用户信息从文件中取出
(2)对用户进行核对,用户存在的情况下允许登录,否则不允许登录
(3)登录的时候的还是要校验密码 : 必须是 6 位 ,并且字母和数据混合 ---> 提高数据的安全等级
3 取款
4 转账
5 查看信息
6 查看日志
总要求:每次操作都有日志记录,每个用户日志数据分开记录
函数多用return少用else
import time, random, re, datetime
user_dict = {}
card_dict = {}
login_now = ''
admin_code = 'qaz123'
def read(file, tag='user'):
if tag == 'user':
try:
with open(file, 'r', encoding='utf8') as f:
data = f.readlines()
for line in data:
data_list = line.strip().split('--')
name, pwd, born, balance, card_num, role, withdraw_password, locked, create_time = data_list
user_dict[name] = {'name': name, 'login_password': pwd, 'borned': born, 'balance': balance,
'card_num': card_num,
'role': role, 'withdraw_password': withdraw_password, 'locked': locked,
'create_time': create_time}
return True, user_dict
except:
return False, {}
if tag == 'diary':
try:
with open(file, 'r', encoding='utf8') as f:
data_str = f.readlines()
return True, data_str
except:
return False, ''
print(read('ATMuser.txt'))
def write(data, file, mode):
if mode == 'a':
with open(file, mode, encoding='utf8') as f:
data_str = '--'.join(i for i in list(data.values())) + '\n'
f.write(data_str)
elif mode == 'w':
with open(file, mode, encoding='utf8') as f:
data_list = [list(i.values()) for i in data.values()]
data_str = '\n'.join('--'.join(i) for i in data_list) + '\n'
f.write(data_str)
else:
with open(file, 'a', encoding='utf8') as f:
f.write(data)
def name_pass():
for i in range(3):
name = input(f'please input your username:').strip()
pwd = input(f'please input your password:').strip()
if len(name) < 3 or len(name) > 8:
print(f'''the length of username should be 3-8,
you have {2 - i} chances left, please try again:''')
continue
elif not re.match('(?