Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. from hashlib import sha256
  2. from base64 import b64encode, b64decode
  3.  
  4. # salt size = 12
  5. SALT_SIZE = 12
  6.  
  7. def hashPassword(password, salt):
  8. ctx = sha256(password)
  9. ctx.update(salt)
  10.  
  11. hash = b"{SSHA256}" + b64encode(ctx.digest() + salt)
  12.  
  13. hash_clean = b64encode(ctx.digest() + salt)
  14.  
  15. print("\nattribute: SSHA2-256-Password")
  16. print("NB: save in the DB without {..}\n")
  17.  
  18. print("sha256 + salt = " + str(ctx.hexdigest() + str(salt)))
  19. print("hashed_password = " + str(hash_clean))
  20.  
  21. return hash_clean
  22.  
  23. def checkPassword(challenge_password, password):
  24. print("\n\nChecking password: " + str(challenge_password))
  25.  
  26. decoded_hash = b64decode(challenge_password)
  27. salt = decoded_hash[32:]
  28. digest = decoded_hash[:-12]
  29.  
  30. hashed_password = sha256(password + salt)
  31.  
  32. print("Password is correct? " + str(hashed_password.digest() == digest))
  33. return hashed_password.digest() == digest
  34.  
  35. hash = hashPassword(b"test", b"saltsaltsalt")
  36. checkPassword(hash, b"test")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement