python新人一月工资_python【项目】:工资管理(简易版)
1 #!/usr/bin/env python
2 #coding=utf-8
3 __author__ = 'yinjia'
4
5 importhashlib6 importsys7 from project.day2 importPayrollSystem8
9 #存儲文件
10 filename = 'log.txt'
11 #賬號信息表
12 result ={}13
14 defmd5(arg):15 """
16 密碼進行md5加密17 :param arg: 用戶的密碼18 :return: 返回進行加密后的密碼19 """
20 result = hashlib.md5(bytes("k1:1a2 k2:688",encoding='utf-8'))21 result.update(bytes(arg,encoding='utf-8'))22 returnresult.hexdigest()23
24
25 deflogin(username,password):26 """
27 用于驗證用戶密碼28 :param username:用戶名29 :param password:密碼30 :return: True,用戶名驗證成功;False,用戶驗證失敗31 """
32
33 with open(filename,"r") as f:34 for line inf:35 u,p = line.strip().split(":")36 if username == u and md5(password) ==p:37 returnTrue38 returnFalse39
40 defregister(username,password):41 """
42 用戶注冊43 :param username: 用戶名44 :param password: 密碼45 :return: True,用戶注冊成功;46 """
47
48 with open(filename,"a") as f:49 temp = "\n" + username + ":" +md5(password)50 f.write(temp)51 returnTrue52
53 defuser_exist(username):54 """
55 檢查用戶名是否存在56 :param username: 用戶名57 :return: True,用戶名存在; False,用戶名不存在58 """
59 with open(filename,"r") as f:60 for line inf:61 line =line.strip()62 line_list = line.split(":")63 if username ==line_list[0]:64 returnTrue65 returnFalse66
67 defdelete(username):68 """
69 刪除用戶名70 :param username: 用戶名71 :return: True,刪除成功; False,刪除失敗72 """
73 info()74 delresult[username]75 with open(filename,'w') as f:76 for key,value inresult.items():77 f.write("%s%s%s\n" % (key,":",value))78 returnTrue79
80 defedit(username,old_password,new_password):81 """
82 修改密碼83 :param username:用戶名84 :param old_password:舊密碼85 :param new_password:新密碼86 :return:True,修改成功;False,修改失敗87 """
88 info()89 ret =result[username]90 if ret ==md5(old_password):91 result[username] =md5(new_password)92 with open(filename, 'w') as f:93 for key, value inresult.items():94 f.write("%s%s%s\n" % (key, ":", value))95 returnTrue96
97 definfo():98 """
99 提取賬號信息100 :return: 返回賬號信息表101 """
102 with open(filename,'r') as f:103 for line inf:104 line =line.strip()105 result[line.split(":")[0]] = line.split(":")[1]106 returnresult107
108 defmain():109 info_msg = """
110 1、登錄系統111 2、注冊賬號112 3、刪除賬號113 4、修改密碼114 """
115
116 print('\033[32;1m')117 print('*' * 50)118 print('\t\t\t\t歡迎登錄工資管理系統')119 print('*' * 50)120 print('\033[0m')121 print(info_msg)122 pingtai = str(input("\033[1;34;1m請選擇操作(退出請輸入q|Q):\033[0m")).strip()123 if pingtai == "1":124 user = input("請輸入用戶名:")125 pwd = input("請輸入密碼:")126 ret =login(user,pwd)127 ifret:128 print("\033[1;31;1m<<<<<<<<登錄成功>>>>>>>>>\033[0m")129 info =PayrollSystem.salary()130 info.comm()131 else:132 print("\033[1;31;1m<<<<<<<<登錄失敗>>>>>>>>>\033[0m")133 elif pingtai == "2":134 user = input("請輸入用戶名:")135 pwd = input("請輸入密碼:")136 ret =user_exist(user)137 ifret:138 print("\033[1;31;1m用戶名已存在,不能注冊!\033[0m")139 else:140 add_user =register(user,pwd)141 ifadd_user:142 print("注冊成功")143 else:144 print("注冊失敗")145 elif pingtai == "3":146 user = input("請輸入用戶名:")147 del_user1 =user_exist(user)148 ifdel_user1:149 del_user2 =delete(user)150 ifdel_user2:151 print("刪除成功!")152 else:153 print("刪除失敗!")154 else:155 print("\033[1;31;1m用戶名不存在,無法刪除!\033[0m")156
157 elif pingtai == "4":158 user = input("請輸入用戶名:")159 pas1 = input('請輸入舊密碼:')160 pas2 = input('請輸入新密碼:')161 del_user =user_exist(user)162 ifdel_user:163 edit_user =edit(user,pas1,pas2)164 ifedit_user:165 print("修改密碼成功!")166 else:167 print("\033[1;31;1m舊密碼錯誤,修改密碼失敗!\033[0m")168 else:169 print("\033[1;31;1m用戶名不存在,無法修改!\033[0m")170 elif str(pingtai).lower() == "q":171 print("GoodBye!")172 sys.exit()173 else:174 print("\033[1;31;1m非法輸入!\033[0m")175
176 if __name__ == "__main__":177 main()
總結
以上是生活随笔為你收集整理的python新人一月工资_python【项目】:工资管理(简易版)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python plot画图_1. 用Py
- 下一篇: python 需要多久能够学精通_pyt