import os import pandas as pd def md5(string:str=''): import hashlib md5 = hashlib.md5() md5.update(string.encode('utf-8')) return md5.hexdigest() # I ...
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):