-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1119.py
More file actions
50 lines (36 loc) · 1009 Bytes
/
Copy path1119.py
File metadata and controls
50 lines (36 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import struct
'''
def is_bmp(file):
try:
with open(file,'rb') as f:
s = f.read(30)
atr = struct.unpack('<ccIIIIIIHH',s)
if atr[0] == b'B' and atr[1] == b'M'
return atr[2],atr[6],atr[7]
else:
raise BaseException
except BaseException:
print (file + 'is not a bmp file')
'''
import hashlib
md5 = hashlib.md5()
md5.update('how to use md5 in python hashlib?'.encode('utf-8'))
print (md5.hexdigest())
db = {}
def register(username,password):
db[username] = get_md5(password + username + 'the - Salt')
def get_md5(str):
md5 = hashlib.md5()
md5.update(str.encode('utf-8'))
return md5.hexdigest()
def login(username,password):
if username in db:
print ('用户名存在,准备验证密码')
if db[username] == get_md5(password + username + 'the - Salt'):
print ('密码正确,登录成功')
else:
print ('密码错误,请重新输入')
else:
print ('用户名不存在')
register('Jane','janejiang')
login ('Jane','janelu')