From 9001204c9e86276b1aa3734653c412d435b0be95 Mon Sep 17 00:00:00 2001 From: Andrea Zucchelli Date: Thu, 9 Feb 2017 22:53:54 +0100 Subject: [PATCH] Password manager --- password_manager.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 password_manager.py 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)) +