import os
import pandas as pd
def md5(string:str=''):
import hashlib
md5 = hashlib.md5()
md5.update(string.encode('utf-8'))
return md5.hexdigest()
# In [1]: def md5(string:str=''):^M
# ...: import hashlib^M
# ...: md5 = hashlib.md5()^M
# ...: md5.update(string.encode('utf-8'))^M
# ...: return md5.hexdigest()^M
# ...: md5('Hello World')^M
# Out[1]: 'b10a8db164e0754105b7a99be72e3fe5'
class Admin():
def init():
if os.path.exists('admin.csv'):
os.remove('admin.csv')
def __init__(self,
admin_username:str='',
admin_name:str='',
admin_idcard:str='',
admin_telephone:str='',
admin_email:str='',
admin_job:str='',
admin_banknum:str='',
admin_password:str=''):
self.admin_username = admin_username
self.admin_password = admin_password
df = pd.read_csv('admin.csv',dtype=str)
admin_password = list(df[df['admin_username']==admin_username]['admin_password'])[0]
if md5(self.admin_password) == admin_password:
self.admin_name = admin_name
self.admin_idcard = admin_idcard
self.admin_telephone = admin_telephone
self.admin_email = admin_email
self.admin_job = admin_job
self.admin_banknum = admin_banknum
else:
print('用户名或密码输入有误!')
exit()
def add_admin(self,
admin_username:str='',
admin_name:str='',
admin_idcard:str='',
admin_telephone:str='',
admin_email:str='',
admin_job:str='',
admin_banknum:str='',
admin_password:str=''):
df = pd.read_csv('admin.csv',dtype=str)
if admin_username not in list(df['admin_username']):
dfi = pd.DataFrame({
'admin_username':[admin_username],
'admin_name':[admin_name],
'admin_idcard':[admin_idcard],
'admin_telephone':[admin_telephone],
'admin_email':[admin_email],
'admin_job':[admin_job],
'admin_banknum':[admin_banknum],
'admin_password':[md5(admin_password)]},
dtype=str)
df = pd.concat([df,dfi])
df.to_csv('admin.csv',encoding='utf-8',index=None)
else:
input('账户已存在,回车取消添加。')
def set_admin(self,column,value):
df = pd.read_csv('admin.csv',dtype=str)
index = df.index[df['admin_username']==self.admin_username]
df.loc[index,[column]] = value
df.to_csv('admin.csv',encoding='utf-8',index=None)
def del_admin(self):
df = pd.read_csv('admin.csv',dtype=str)
index = df.index[df['admin_username']!=self.admin_username]
df = df.loc[index,:]
df.to_csv('admin.csv',encoding='utf-8',index=None)
def cat_admin(self):
df = pd.read_csv('admin.csv',dtype=str)
df = df[df['admin_username'] == self.admin_username]
print(df)
def test():
admin = Admin(admin_username='0000',admin_password='123456')
admin.cat_admin()
admin.set_admin('admin_name','毛麟')
admin.add_admin(admin_username='0001',admin_password='123456')
admin = Admin(admin_username='0002',admin_password='123456')
admin.del_admin()
def admin_login():
print('欢迎进入毛子哥银行管理员系统登录页面:')
for i in range(3):
admin_username = input('请输入管理员登录账户:')
admin_password = input('请输入管理员登录密码:')
df = pd.read_csv('admin.csv',encoding='utf-8',dtype=str)
password = list(df[df['admin_username']==admin_username]['admin_password'])[0]
if md5(admin_password) == password:
admin = Admin(admin_username=admin_username,admin_password=admin_password)
os.system('cls')
return admin
else:
os.system('cls')
print('哦豁,密码输错了进不去,难受!!!')
continue
os.system('cls')
print('密码这种东西都会忘,干脆把名字也一起忘了吧。')
exit()
def admin_main():
if not os.path.exists('admin.csv'):
df = pd.DataFrame({
'admin_username':['0000'],
'admin_name':[''],
'admin_idcard':[''],
'admin_telephone':[''],
'admin_email':[''],
'admin_job':[''],
'admin_banknum':[''],
'admin_password':[md5('123456')]},
dtype=str)
df.to_csv('admin.csv',encoding='utf-8',index=None)
admin = admin_login()
while True:
os.system('cls')
print('''欢迎进入毛子哥银行管理员系统:
本系统提供以下功能:
1.添加用户;2.查看用户;3.修改用户;
4.切换用户;5.删除用户;6.退出系统。''')
menu = input('请输入你想要操作的功能编号:')
if menu == '1':
os.system('cls')
print('欢迎使用毛子哥银行管理员系统添加用户功能:')
admin_username = input('请输入登陆账号:')
admin_password = input('请输入登录密码:')
admin.add_admin(admin_username=admin_username,admin_password=admin_password)
elif menu == '2':
os.system('cls')
print('欢迎使用毛子哥银行管理员系统查看用户功能:')
admin.cat_admin()
input('回车取消查看。')
elif menu == '3':
os.system('cls')
print('欢迎使用毛子哥银行管理员系统修改用户功能:')
column = input('请输入当前用户需要修改的字段名字:')
value = input('请输入当前用户需要修改的字段数据:')
admin.set_admin(column,value)
elif menu == '4':
os.system('cls')
condition = input('即将切换毛子哥银行管理员系统账户(y/n):')
if condition == 'y':
admin = admin_login()
elif menu == '5':
os.system('cls')
condition = input('即将删除毛子哥银行管理员系统账户(y/n):')
if condition == 'y':
admin.del_admin()
continue
elif menu == '6':
os.system('cls')
condition = input('即将离开毛子哥银行管理员系统(y/n):')
break
def main():
admin_main()
if __name__ == '__main__':
main()