python_hashlib模块
1 网站登陆
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 import random 2 import string 3 import pickle 4 5 # data1 = string.ascii_letters 6 # print("data1数据类型:%s->数据内容:%s" % (type(data1), data1)) 7 # 8 # data2 = string.digits 9 # print("data2数据类型:%s->数据内容:%s" % (type(data2), data2)) 10 # 11 # data3 = random.sample((data1 + data2), 6) 12 # print("data3数据类型:%s->数据内容:%s" % (type(data3), data3)) 13 # 14 # data4 = ''.join(data3) 15 # print("data4数据类型:%s->数据内容:%s" % (type(data4), data4)) 16 17 # text = "李陵没胡沙,\n苏武还汉家。\n迢迢五原关,\n朔雪乱边花。\n一去隔绝国,思归但长嗟。鸿雁向西北,因书报天涯。" 18 # 19 # with open('text_test', 'ab') as f: 20 # pickle.dump(text, f) 21 22 # def get_data(): 23 # with open('text_test', 'rb') as f: 24 # data = pickle.load(f) 25 # yield data 26 # 27 # data_text = get_data() 28 # for i, data in enumerate(data_text): 29 # print(i, '->', data) 30 31 32 # data_dic = {'id': {'username': 'admin', 'password': '123456'}, 'name': 'alex', 'age': 18} 33 # for data in data_dic: 34 # print(data) 35 # 36 # req = data_dic["id"] 37 # print(req['username']) 38 39 import hashlib 40 41 42 def md5(arg): 43 md5_pwd = hashlib.md5(bytes('abd', encoding='utf-8')) 44 md5_pwd.update(bytes(arg, encoding='utf-8')) 45 return md5_pwd.hexdigest() 46 47 def log(user, pwd): 48 with open('db', 'r', encoding='utf-8') as f: 49 for line in f: 50 u, p = line.strip().split('|') 51 if u == user and p == md5(pwd): 52 return True 53 54 def register(user, pwd): 55 with open('db', 'a', encoding='utf-8') as f: 56 temp = user + '|' + md5(pwd) 57 f.write(temp) 58 59 60 i = input('1表示登陆,2表示注册:') 61 if i == '2': 62 user = input('用户名:') 63 pwd = input('密码:') 64 register(user, pwd) 65 elif i == '1': 66 user = input('用户名:') 67 pwd = input('密码:') 68 r = log(user, pwd) 69 if r == True: 70 print('登陆成功') 71 else: 72 print('登陆失败') 73 else: 74 print('账号不存在')
2 个人笔记
无论是专业编程人员还是个人爱好,python语法即使非常熟悉,我们还是不会完成自己的想法,因为我们不会结构化的思维,不会组合,解决这个问题的办法就是多练习,坚持练习,多看别人的优秀代码,不要停下来。
对python编程有着深入骨髓的喜爱,没有python就吃不下饭,睡觉?还想睡什么觉啊,使劲虐啊,年纪轻轻就好好学python。
学习python要讲究方法和逻辑,要有结构的化的思维。
之前老是听别人说:改变自己的是自我对待事物的态度,态度是什么,就是类啊,里面包含着你的坚持,你的兴趣,你的学习,你的一切。
思路来源:
https://www.cnblogs.com/xiaobeibei26/p/6422012.html