-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpass.py
More file actions
54 lines (41 loc) · 1.14 KB
/
pass.py
File metadata and controls
54 lines (41 loc) · 1.14 KB
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
47
48
49
50
51
52
53
import hashlib,os
os.chdir('C:\python_test')
DIR=os.getcwd()
FILE=os.path.join(DIR,'pass.txt')
db={}
def load_db():
with open(FILE,'r') as file:
for line in file.readlines():
line=line.strip('\n')
db[line.split(',')[0]]=line.split(',')[-1]
def calc_md5(password):
password=password+' The salt'
md5=hashlib.md5()
md5.update(password.encode('utf-8'))
return md5.hexdigest()
def register(username,password):
db[username]=calc_md5(password)
def login(username,password):
if db[username] == password:
return "Welcome {}!".format(username)
else:
return "Bad password!"
if __name__=="__main__":
username=input('Please input your username:')
# password=input('Please input your password:')
# username='Jian'
load_db()
if username not in db:
password=input('Please input your new password:')
# password='12345678'
password=calc_md5(password)
with open(FILE,'a') as file:
file.write("\n{},{}".format(username,password))
input('Please relogin with your new password,')
exit()
password=input('Please input your password:')
password=calc_md5(password)
# print(password)
# print(db)
print(login(username,password))
input('')