-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_md5.py
42 lines (35 loc) · 990 Bytes
/
calc_md5.py
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
# !/usr/bin/env python
# -*- utf-8 -*-
import hashlib
db = {}
salt = 'pythonisbest'
def get_md5(password):
pw_md5 = hashlib.md5()
pw_md5.update(password.encode('utf-8'))
return pw_md5.hexdigest()
def register():
print('请注册:')
user = input('Please input your username: ')
if user in db:
print(user + 'is already registed!')
print('请登录:')
else:
passwd = input('Please input your password: ')
db[user] = get_md5(user + passwd + salt)
print('注册成功,请登录:')
login()
def login():
user = input('Please input user: ')
if user in db:
passwd = input('Please input password: ')
password = get_md5(user + passwd + salt)
if password == db[user]:
print('登录成功!')
else:
print('密码错误!')
print('重新登录')
login()
else:
print('User not exist!')
register()
register()