Thanks to the openldap project
#!/usr/bin/env python import hashlib import os from base64 import encodestring as encode from base64 import decodestring as decode import getpass def makeSecret(password): salt = os.urandom(4) h = hashlib.sha1(password) h.update(salt) return "{SSHA}" + encode(h.digest() + salt) def checkPassword(challenge_password, password): challenge_bytes = decode(challenge_password[6:]) digest = challenge_bytes[:20] salt = challenge_bytes[20:] hr = hashlib.sha1(password) hr.update(salt) return digest == hr.digest() if __name__ == "__main__": pass1 = getpass.getpass() pass2 = getpass.getpass() if pass1 == pass2: ver = makeSecret(pass1) print ver bol = checkPassword(ver,pass1) print bol else: print "pass are not equals"
No comments:
Post a Comment