rudemaps/password_manager.py

17 lines
528 B
Python

import hashlib
import os
import binascii
__ROUNDS=100000
def gen_salt(size=16):
return binascii.hexlify(os.urandom(size))
def encrypt_password(password,salt=None):
salt=binascii.unhexlify(salt) if salt else ''
return binascii.hexlify(hashlib.pbkdf2_hmac("sha512",password,salt,__ROUNDS))
def check_password(encrypted_password,clear_password,salt=None):
salt=binascii.unhexlify(salt) if salt else ''
return encrypted_password==binascii.hexlify(hashlib.pbkdf2_hmac("sha512",clear_password,salt,__ROUNDS))