diff --git a/password_manager.py b/password_manager.py new file mode 100644 index 0000000..d0e91fb --- /dev/null +++ b/password_manager.py @@ -0,0 +1,17 @@ +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)) +