aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask/pbkdf2.py
blob: 1a965fc596aea76ed8ed31fb2b442d3cda486539 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import hashlib

from werkzeug.security import safe_str_cmp as ssc

# Replace this because it just wraps around Python3's internal
# functions. Added this during migration.


def pbkdf2_hex(data, salt, iterations=1000, keylen=24, hashfunc="sha1"):
    """Wrapper function of python's hashlib.pbkdf2_hmac.
    """

    dk = hashlib.pbkdf2_hmac(hashfunc,
                             bytes(data, "utf-8"),  # password
                             salt,
                             iterations,
                             keylen)
    return dk.hex()


def safe_str_cmp(a, b):
    return ssc(a, b)