-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.py
44 lines (39 loc) · 991 Bytes
/
user.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
42
43
44
import pycouchdb
import hashlib
import binascii
def get_user_data(
server_url,
username,
):
server = pycouchdb.Server(server_url)
users_db = server.database('_users')
user_id = f"org.couchdb.user:{username}"
try:
user_data = users_db.get(user_id)
return user_data
except pycouchdb.exceptions.NotFound:
print("User not found.")
return None
except Exception as e:
print(f"An error occurred: {e}")
return None
# based on https://github.com/perfood/couch-pwd/blob/master/index.js
def get_password_hash(
pwd: str,
salt: str,
iterations=10,
keylen=20,
digest='SHA1'
) -> str:
if not pwd:
raise ValueError('password missing')
if not salt:
raise ValueError('salt missing')
hash_bytes = hashlib.pbkdf2_hmac(
digest.lower(),
pwd.encode(),
salt.encode(),
iterations,
keylen
)
return binascii.hexlify(hash_bytes).decode()