簡單自定義Annotation和利用反射獲取註解中的值
阿新 • • 發佈:2021-06-28
1 """ 2 1、第一個 3 usernames = ["admin","test","dev"] 4 password = ["111","222","333"] 5 input("username:") 6 input("password:") 7 1、最多輸入3次,超過3次提示錯誤次數過多 8 2、輸入賬號/密碼正確,提示歡迎xxx登入,今天的日期是xxx,程式結束 9 3、如果輸入為空要提示,輸入不能為空 (查一下字串方法),算錯誤一次10 4、如果輸入賬號不存在,要提示,算錯誤一次 11 5、密碼輸入錯誤也算一次 12 13 """ 14 """ 15 user_info = 16 { 17 "admin":"111", 18 "test":"222", 19 "dev":"333" 20 } 21 1、最多輸入3次,超過3次提示錯誤次數過多 22 2、輸入賬號/密碼正確,提示歡迎xxx登入,今天的日期是xxx,程式結束23 3、如果輸入為空要提示,輸入不能為空 (查一下字串方法),算錯誤一次 24 4、如果輸入賬號不存在,要提示,算錯誤一次 25 5、密碼輸入錯誤也算一次 26 """ 27 import datetime 28 usernames = ["admin", "test", "dev"] 29 passwords = ["111", "222", "333"] 30 31 user_info = { 32 "admin": "111", 33 "test": "222", 34 "dev": "333" 35 } 36 37 38 #list 39 for i in range(3): 40 username = input("username:").strip() 41 password = input("password:").strip() 42 if len(username) == 0 or len(password)==0: 43 print("賬號/密碼不能為空") 44 elif username not in usernames: 45 print("使用者名稱不存在") 46 else: 47 username_index = usernames.index(username) 48 db_password = passwords[username_index] 49 if password == db_password: 50 print("歡迎登陸%s,今天的日期是%s" % (username,datetime.datetime.today())) 51 break 52 else: 53 print("密碼錯誤!") 54 else: 55 print("錯誤次數達到上限!") 56 57 #DICT 58 59 for i in range(3): 60 username = input("username:").strip() 61 password = input("password:").strip() 62 63 if len(username) == 0 or len(password)==0: 64 print("賬號/密碼不能為空") 65 elif username not in user_info: 66 print("使用者名稱不存在") 67 else: 68 db_password = user_info[username] 69 if password == db_password: 70 print("歡迎登陸%s,今天的日期是%s" % (username,datetime.datetime.today())) 71 break 72 else: 73 print("密碼錯誤!") 74 else: 75 print("錯誤次數達到上限!")
1 # 登入 2 """ 登入 login.py,賬號和密碼存在檔案裡面 3 1、最多輸入3次 4 2、username 5 password 6 3、要加非空校驗 7 4、賬號長度在5-10之間,要校驗賬號是否存在,賬號登入的時候不缺分大小寫 8 5、密碼長度在6-12位之間,密碼必須包括數字、大小寫字母、特殊符號 9 6、判斷密碼是否正確,正確的話就登入""" 10 11 # 登入 12 import string, datetime 13 14 FILE_NAME = "user.txt" 15 # 常量 16 user_info = {} 17 f = open(FILE_NAME, encoding="utf-8") 18 lines = f.readlines() 19 for line in lines: 20 line = line.strip() 21 if line: 22 username = line.split(',')[0].lower() 23 password = line.split(',')[1] 24 user_info[username] = password 25 f.close() 26 27 #登入交集的方法 28 29 # for i in range(3): 30 # username = input("username:").strip().lower() 31 # password = input("password:").strip() 32 # if len(username) == 0 or len(password)==0: 33 # print("賬號/密碼不能為空") 34 # elif len(username) <5 or len(username)>10: 35 # print("使用者名稱長度在5-10之間") 36 # elif len(password) not in range(6,13): #6 7 8 9 10 11 12 37 # print("密碼的長度要在6-12直接") 38 # elif not (set(password) & set(string.digits) and set(password) & \ 39 # set(string.ascii_uppercase) and set(password) & set(string.ascii_lowercase) \ 40 # and set(password) & set(string.punctuation)): 41 # print("密碼複雜度不對") 42 # elif username not in user_info: 43 # print("使用者名稱不存在") 44 # else: 45 # db_password = user_info[username] 46 # if password == db_password: 47 # print("歡迎登陸%s,今天的日期是%s" % (username,datetime.datetime.today())) 48 # break 49 # else: 50 # print("密碼錯誤!") 51 # else: 52 # print("錯誤次數達到上限!") 53 54 # d,u,l,p = False #d整數,u是大寫字母 l是小寫字母 p是符號 55 56 # for i in range(3): 57 # username = input("username:").strip().lower() 58 # password = input("password:").strip() 59 # if len(username) == 0 or len(password)==0: 60 # print("賬號/密碼不能為空") 61 # elif len(username) <5 or len(username)>10: 62 # print("使用者名稱長度在5-10之間") 63 # elif len(password) not in range(6,13): #6 7 8 9 10 11 12 64 # print("密碼的長度要在6-12直接") 65 # else: 66 # for i in password: 67 # if i in string.digits: 68 # d = True 69 # elif i in string.ascii_uppercase: 70 # u = True 71 # elif i in string.ascii_lowercase: 72 # l = True 73 # elif i in string.punctuation: 74 # p = True 75 # if not (d and u and l and p): 76 # print("密碼複雜度不對") 77 # elif username not in user_info: 78 # print("使用者名稱不存在") 79 # else: 80 # db_password = user_info[username] 81 # if password == db_password: 82 # print("歡迎登陸%s,今天的日期是%s" % (username,datetime.datetime.today())) 83 # break 84 # else: 85 # print("密碼錯誤!") 86 # else: 87 # print("錯誤次數達到上限!") 88 # 89 90 91 # d,u,l,p = False #d整數,u是大寫字母 l是小寫字母 p是符號 92 # 93 # for i in range(3): 94 # username = input("username:").strip().lower() 95 # password = input("password:").strip() 96 # if len(username) == 0 or len(password)==0: 97 # print("賬號/密碼不能為空") 98 # elif len(username) <5 or len(username)>10: 99 # print("使用者名稱長度在5-10之間") 100 # elif len(password) not in range(6,13): #6 7 8 9 10 11 12 101 # print("密碼的長度要在6-12直接") 102 # else: 103 # for i in password: 104 # if i.isdigit(): 105 # d = True 106 # elif i.upper(): 107 # u = True 108 # elif i.lower(): 109 # l = True 110 # elif not i.isalnum(): 111 # p = True 112 # if not (d and u and l and p): 113 # print("密碼複雜度不對") 114 # elif username not in user_info: 115 # print("使用者名稱不存在") 116 # else: 117 # db_password = user_info[username] 118 # if password == db_password: 119 # print("歡迎登陸%s,今天的日期是%s" % (username,datetime.datetime.today())) 120 # break 121 # else: 122 # print("密碼錯誤!") 123 # else: 124 # print("錯誤次數達到上限!") 125 126 127 """註冊 reg.py 128 #賬號和密碼存在檔案裡面 129 #1、最多輸入3次 130 #2、username 131 password 132 cpwd 133 3、要加非空校驗 134 4、賬號長度在5-10之間,賬號不能重複,賬號註冊的時候不缺分大小寫 135 5、兩次輸入的密碼要一致,密碼長度在6-12位之間,密碼必須包括數字、大小寫字母、特殊符號 136 6、通過校驗之後,賬號和密碼存到檔案裡面""" 137 138 import string, datetime 139 140 FILE_NAME = "user.txt" 141 # 常量 142 user_info = {} 143 f = open(FILE_NAME, encoding="utf-8") 144 lines = f.readlines() 145 for line in lines: 146 line = line.strip() 147 if line: 148 username = line.split(',')[0].lower() 149 password = line.split(',')[1] 150 user_info[username] = password 151 f.close() 152 153 154 for i in range(3): 155 username = input("username:").strip().lower() 156 password = input("password:").strip() 157 cpassword = input("cpassword:").strip() 158 if len(username) == 0 or len(password)==0 or len(cpassword) == 0: 159 print("賬號/密碼/確認密碼不能為空") 160 elif len(username) <5 or len(username)>10: 161 print("使用者名稱長度在5-10之間") 162 elif len(password) not in range(6,13) : #6 7 8 9 10 11 12 163 print("密碼的長度要在6-12直接") 164 elif password != cpassword: 165 print("確認密碼要和密碼一致") 166 elif not (set(password) & set(string.digits) and set(password) & \ 167 set(string.ascii_uppercase) and set(password) & set(string.ascii_lowercase) \ 168 and set(password) & set(string.punctuation)): 169 print("密碼複雜度不對") 170 elif username in user_info: 171 print("使用者名稱已經存在") 172 else: 173 f = open(FILE_NAME,'a',encoding="utf-8") 174 f.write("%s,%s\n" % (username,password)) 175 f.close() 176 print("註冊成功!") 177 break 178 else: 179 print("錯誤次數達到上限!")