新手写的代码:
CASH MANAGER
包含存钱、取款、查余额、查明细、清除数据等。
缺点是密码裸露,为进行伪装
全部代码在这里:
# 愿我的代码能顺利跑起来。
# 写在前面的话:
# 别乱动代码!改动前仔细看注释!
import tqdm
import os
import time
import random
import string
# 系统时间代码
TimeNow = time.strftime('%Y-%m-%d %H:%M:%S')
print('''
****************************************************
* *
* A.H.N CASH MANAGER *
* IRRIGATION BIRD.INC 2022 *
* *
* *
****************************************************
''')
print(f'日期时间:{TimeNow} 系统版本:1.30 Preview')
def file_exam():
"""
参数说明:
-DataReadline:开机系统加载后读取 f.readline()时的临时变量
"""
for _ in tqdm.tqdm(range(30), desc='[系统文件检测]', ncols=70, colour='blue', leave=False):
time.sleep(0.05)
# 如果系统文件,存在则读取账户名称,账户密码和资产数据等并返回
if os.path.isfile('acc.db'):
f = open('acc.db', 'r')
print('[系统文件检测通过]')
time.sleep(0.5)
print('[准备加载账户数据]')
time.sleep(0.5)
for _ in tqdm.tqdm(range(30), desc='[加载文件数据]', ncols=70, colour='blue', leave=False):
time.sleep(0.05)
#print('OK')
# 读取系统文件内容
f = open('acc.db', 'r')
DataReadline = f.readline()
#print(DataReadline)
if DataReadline == 'K':
print('[系统数据损坏且无法进行修复]')
print('[可能由于系统执行过数据清除]')
time.sleep(0.5)
print('[开始启动数据文件保护程序]')
time.sleep(0.5)
for _ in tqdm.tqdm(range(1000), desc='[数据文件保护]', ncols=70, colour='blue', leave=False):
time.sleep(0.05)
for _ in range(8):
savecode = random.sample(string.ascii_uppercase + string.digits, 8)
#print(savecode)
savecode_ = ''.join(savecode)
#print(savecode_)
savecode__ = '#' + savecode_
f = open('acc.db', 'w')
f.write(savecode__)
f.close()
print('[请牢记保护代码]')
print(savecode__[1:])
print()
input('[请记录保护代码后按任意键开始下一步]:')
print('[请将保护代码输入CASH MANAGER REPAIR MASTER 进行系统文件修复]')
time.sleep(1)
print('[请不要关闭程序][等待程序自动退出]')
time.sleep(5)
exit('[再见]')
# 判断系统文件是否符合以下要求:
# 1.数据列总长度必须是4 2.密码长度为6 且均为数字 3.金额必须为浮点型
# 以上有一点不符合则执行文件修复程序
elif DataReadline == '':
dataRepair()
elif DataReadline == None:
dataRepair()
elif not DataReadline[-1].isdigit():
dataRepair()
elif len(DataReadline) < 19:
dataRepair()
# 所有检查字符串切片的判断必须要从这里开始
elif DataReadline[0] == '#':
print('[系统数据损坏无法修复且已获得保护]')
print('[请将保护代码输入 CASH MANAGER REPAIR MASTER 开始修复]')
time.sleep(5)
exit('[再见]')
# 系统文件正常时,直接读取并返回账户数据
else:
f = open('acc.db', 'r')
for DataLine in f:
DataLine = DataLine.split(',')
UserNameLoad = DataLine[0]
PasswordLoad = DataLine[1]
MoneyLoad = DataLine[2]
SafeLock = DataLine[3]
return UserNameLoad, PasswordLoad, MoneyLoad, SafeLock
# 未检测到系统文件时,开始新用户注册,注册成功后返回账户数据
else:
print('-' * 50)
print('[未检测到系统文件]')
time.sleep(0.5)
print('[开始新用户注册程序]')
f = open('acc.db', 'w')
while True:
UserName = input('[请设置账户名称][注意区分大小写]:').strip()
if len(UserName) != 6:
print('[账户名称长度规定为六位]')
continue
else:
while True:
Password_1 = input('[请设置账户密码][长度为六位数字]:').strip()
if not Password_1.isdigit():
print('[账户密码必须都是数字]')
continue
elif len(Password_1) != 6:
print('[账户密码长度必须是六位]')
continue
Password_2 = input('[请确认账户密码]:').strip()
if Password_1 == Password_2:
print('[账户注册成功]')
PersonData = [UserName, Password_2, '0.00', '0']
PersonData = ','.join(PersonData)
f.write(PersonData)
for _ in tqdm.tqdm(range(50), desc='[账户信息注册]', ncols=70, colour='blue', leave=False):
time.sleep(0.05)
f.close()
return UserName, Password_2, '0.00', '0'
else:
print('[两次密码输入不一致][请重新输入]')
continue
# 账户修复函数
def dataRepair():
print('-' * 50)
print('[**警告**][检测到系统文件损坏]')
time.sleep(0.5)
print('[开始启动账户自动修复程序]')
print('[由于数据丢失或损坏][您的帐户即将被重置]')
time.sleep(0.5)
for _ in tqdm.tqdm(range(1000), desc='[正在重置账户]', ncols=70, colour='blue', leave=False):
time.sleep(0.05)
print('-' * 50)
print('[账户重置完成]')
f = open('acc.db', 'w')
while True:
TempName = input('[请设置紧急重置账户名称]:').strip()
if len(TempName) != 6:
print('[账户名称长度规定为六位]')
continue
else:
while True:
TempPassword_1 = input('[请设置紧急重置账户密码][长度为六位数字]:').strip()
if not TempPassword_1.isdigit():
print('[账户密码必须都是数字]')
continue
elif len(TempPassword_1) != 6:
print('[账户密码长度必须是六位]')
continue
TempPassword_2 = input('[请确认紧急重置账户密码]:').strip()
if TempPassword_1 == TempPassword_2:
print('[紧急账户设置成功]')
TempData = [TempName, TempPassword_2, '0.00', '0']
TempData = ','.join(TempData)
f.write(TempData)
f.close()
time.sleep(3)
exit('[再见]')
else:
print('[两次密码输入不一致][请重新输入]')
continue
def login(LoginName, LoginPassword, LoginSafeLock):
print('-' * 50)
print('[用户登录]')
if LoginSafeLock == '1':
print('[您的账户已被锁定]')
time.sleep(3)
exit('[再见]')
else:
while True:
UName = input('[请输入账户名称]:').strip()
if UName == LoginName:
print('-' * 50)
count = 0
while count < 3:
PWord = input('[请输入账户密码]:').strip()
if PWord == LoginPassword:
print('[账户登录成功]')
return LoginName, LoginPassword, LoginSafeLock
else:
print('[密码输入错误]')
print(f'[三次密码输入错误账户将被锁定][剩余{2 - count}次]')
count += 1
continue
print('[您的账户已被锁定]')
time.sleep(3)
LoginSafeLock = '1'
return LoginName, LoginPassword, LoginSafeLock
else:
print('[账户名称错误]')
def startscreen(UM):
print('-' * 50)
print(f'欢迎[{UM}] [{TimeNow}]')
print('''[业务种类]
[标注 * 表示该功能暂不可用]
[1.现金存入 2.账户取款 3.明细查询]
[4.修改密码 5.数据清除 *.数据导出]
[7.余额查询 8.关于软件 0.退出程序]
''')
print('-' * 50)
while True:
Choise = input('[请选择业务代码]:').strip()
if Choise.isdigit():
Choise = int(Choise)
if 0 <= Choise < 9:
return Choise
else:
print('[业务代码输入错误]')
continue
else:
print('[业务代码必须是数字]')
continue
def business(N, P, M):
if N == 0:
exit('[再见]')
elif N == 1:
print('[现金存入]')
SaveMoney = input('[请输入存入的金额]:').strip()
if SaveMoney.count('.') == 1:
M = float(M)
M = round(M, 2)
SaveMoneyList = SaveMoney.split('.')
SaveMoneyStr = ''.join(SaveMoneyList)
if SaveMoneyStr.isdigit():
SaveMoney = float(SaveMoney)
SaveMoney = round(SaveMoney, 2)
M += SaveMoney
M = str(M)
print(f'[您已存入:{SaveMoney}元][当前余额:{M}元]')
f = open('data.db', 'a', encoding='GBK')
SaveTime = time.strftime('%Y-%m-%d %H:%M')
SaveMoney = str(SaveMoney)
SaveData = [SaveTime, '存入', SaveMoney, M]
SaveDataWrite = ' '.join(SaveData)
f.write(f'{SaveDataWrite}\n')
f.close()
return P, M
else:
print('[金额格式错误]')
return P, M
else:
print('[金额必须精确到小数点后两位]')
return P, M
elif N == 2:
print('[账户取款]')
LoadMoney = input('[请输入取出的金额]:').strip()
if LoadMoney.count('.') == 1:
M = float(M)
M = round(M, 2)
LoadMoneyList = LoadMoney.split('.')
LoadMoneyStr = ''.join(LoadMoneyList)
if LoadMoneyStr.isdigit():
LoadMoney = float(LoadMoney)
LoadMoney = round(LoadMoney, 2)
if LoadMoney <= M:
M -= LoadMoney
M = str(M)
print(f'[您已取出:{LoadMoney}元][当前余额:{M}元]')
f = open('data.db', 'a', encoding='GBK')
LoadTime = time.strftime('%Y-%m-%d %H:%M')
LoadMoney = str(LoadMoney)
LoadData = [LoadTime, '取出', LoadMoney, M]
LoadDataWrite = ' '.join(LoadData)
f.write(f'{LoadDataWrite}\n')
f.close()
return P, M
else:
print('[账户余额不足]')
M = str(M)
return P, M
else:
print('[金额格式错误]')
return P, M
else:
print('[金额必须精确到小数点后两位]')
return P, M
elif N == 3:
print('[明细查询]')
if os.path.isfile('data.db'):
print(' [日期] [项目 金额 余额]')
f = open('data.db', 'r')
for line in f:
print(line, end='')
return P, M
elif N == 4:
print('[修改密码]')
OldPassword = input('[请输入旧密码]:').strip()
if OldPassword == P:
NewPassword_1 = input('[请输入新密码]:').strip()
NewPassword_2 = input('[请确认新密码]:').strip()
if NewPassword_1 == NewPassword_2:
print('[密码修改成功]')
return NewPassword_2, M
else:
print('[两次密码输入不一致][密码修改失败]')
return P, M
else:
print('[密码验证错误][返回主菜单]')
return P, M
elif N == 5:
print('[数据清除]')
print('[警告][数据清除后无法恢复][请输入清除代码进行确认]')
ClearCode = random.sample(string.ascii_uppercase + string.digits, 6)
ClearCode = ''.join(ClearCode)
Code = input(f'[请输入清除代码开始清除数据] {ClearCode}:').strip()
if Code == ClearCode:
print('[开始进行数据清除]')
time.sleep(0.5)
print('[第一步:清除账户数据]')
time.sleep(0.5)
for _ in tqdm.tqdm(range(1000), desc='[清除账户数据]', ncols=70, colour='red', leave=False):
time.sleep(0.05)
f = open('acc.db', 'w')
f.write('K')
f.close()
print('[账户数据清除完成]')
time.sleep(0.5)
print('[第二步:清除账户明细]')
time.sleep(0.5)
for _ in tqdm.tqdm(range(1000), desc='[清除账户明细]', ncols=70, colour='red', leave=False):
time.sleep(0.05)
f = open('data.db', 'w')
f.write('')
f.close()
print('[全部数据清除已完成]')
time.sleep(0.5)
print('[请不要关闭程序][等待程序自动退出]')
time.sleep(5)
exit('[再见]')
else:
print('[清除代码输入错误][停止数据清除]')
return P, M
elif N == 6:
print('[数据导出]')
print('[该功能暂不可用]')
return P, M
elif N == 7:
print('[余额查询]')
print(f'[当前余额][{M}元]')
print(f'[查询时间][{TimeNow}]')
return P, M
elif N == 8:
print('[关于软件]')
Software = ['代码:边峥同学', '2022年5月21日 主代码框架完成', '2022年5月22日 修复了诸多BUG', '内部版本号:KID']
for i in Software:
print(i)
return P, M
# 主程序运行框架
# step1 系统文件检测和注册程序
UserNameR, PasswordR, MoneyR, SafeLockR = file_exam()
# step2 用户登录
UserNameR, PasswordR, SafeLockR = login(UserNameR, PasswordR, SafeLockR)
# 登录密码错误返回值锁定
if SafeLockR == '1':
f = open('acc.db', 'w')
LockData = [UserNameR, PasswordR, MoneyR, SafeLockR]
LockData = ','.join(LockData)
f.write(LockData)
f.close()
exit('[再见]')
# 业务列表和业务办理
while True:
# 展示业务列表供用户选择
Pick = startscreen(UserNameR)
# 开始业务
PasswordR, MoneyR = business(Pick, PasswordR, MoneyR)
# 每完成业务后重新自动保存数据
BusinessOver = [UserNameR, PasswordR, MoneyR, SafeLockR]
BusinessOver = ','.join(BusinessOver)
f = open('acc.db', 'w')
f.write(BusinessOver)
f.close()
# 业务完成后稍作停顿
time.sleep(2)
# print(UserNameR, PasswordR, MoneyR, SafeLockR)
# print('OK')
其中注释掉一些用于运行检测是否正常的代码……