password_manager.py 591 B

1234567891011121314151617181920
  1. import hashlib
  2. import os
  3. import binascii
  4. __ROUNDS=100000
  5. def gen_salt(size=16):
  6. return binascii.hexlify(os.urandom(size))
  7. def encrypt_password(password,salt=None):
  8. salt=binascii.unhexlify(salt) if salt else ''
  9. return binascii.hexlify(hashlib.pbkdf2_hmac("sha512",password,salt,__ROUNDS))
  10. def check_password(encrypted_password,clear_password,salt=None):
  11. salt=binascii.unhexlify(salt) if salt else ''
  12. return encrypted_password==binascii.hexlify(hashlib.pbkdf2_hmac("sha512",clear_password,salt,__ROUNDS))
  13. def login_validation(auth,auth_value):
  14. #TBD
  15. return True