Spaces:
Build error
Build error
Commit
4ac2782
• 1
Parent(s):
e23b00b
feat: user chooses token
Browse files- backend/microverses.json +1 -1
- backend/security.py +2 -10
backend/microverses.json
CHANGED
@@ -1 +1 @@
|
|
1 |
-
[]
|
1 |
+
[]
|
backend/security.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
from pathlib import Path
|
2 |
import json
|
3 |
-
import bcrypt
|
4 |
|
5 |
|
6 |
def auth(token):
|
@@ -12,13 +11,8 @@ def auth(token):
|
|
12 |
path = Path('records.json')
|
13 |
|
14 |
if not path.exists():
|
15 |
-
salt = bcrypt.gensalt()
|
16 |
-
hashed_token = bcrypt.hashpw(token.encode(
|
17 |
-
'utf8'), salt).decode('utf8')
|
18 |
-
|
19 |
records = {
|
20 |
-
'
|
21 |
-
'custodian_hashed_token_salt': salt.decode('utf8')
|
22 |
}
|
23 |
json.dump(records, open(path, 'w'))
|
24 |
|
@@ -27,10 +21,8 @@ def auth(token):
|
|
27 |
}
|
28 |
else:
|
29 |
records = json.load(open(path))
|
30 |
-
hashed_token = bcrypt.hashpw(token.encode(
|
31 |
-
'utf-8'), records['custodian_hashed_token_salt'].encode('utf8')).decode('utf8')
|
32 |
|
33 |
-
if records['
|
34 |
return {
|
35 |
'custodian': True
|
36 |
}
|
1 |
from pathlib import Path
|
2 |
import json
|
|
|
3 |
|
4 |
|
5 |
def auth(token):
|
11 |
path = Path('records.json')
|
12 |
|
13 |
if not path.exists():
|
|
|
|
|
|
|
|
|
14 |
records = {
|
15 |
+
'custodian_token': token
|
|
|
16 |
}
|
17 |
json.dump(records, open(path, 'w'))
|
18 |
|
21 |
}
|
22 |
else:
|
23 |
records = json.load(open(path))
|
|
|
|
|
24 |
|
25 |
+
if records['custodian_token'] == token:
|
26 |
return {
|
27 |
'custodian': True
|
28 |
}
|