def passwd_check(hashed_passphrase, passphrase):
 try:
  (algorithm, salt, pw_digest) = hashed_passphrase.split(':', 2)
 except (ValueError, TypeError):
  return False
 try:
  h = hashlib.new(algorithm)
 except ValueError:
  return False
 if (len(pw_digest) == 0):
  return False
 h.update((cast_bytes(passphrase, 'utf-8') + cast_bytes(salt, 'ascii')))
 return (h.hexdigest() == pw_digest)

def passwd_check ( hashed_passphrase , passphrase ) : try : ( algorithm , salt , pw_digest ) = hashed_passphrase . split ( ':' , 2 ) except ( ValueError , TypeError ) : return False try : h = hashlib . new ( algorithm ) except ValueError : return False if ( len ( pw_digest ) == 0 ) : return False h . update ( ( cast_bytes ( passphrase , 'utf-8' ) + cast_bytes ( salt , 'ascii' ) ) ) return ( h . hexdigest ( ) == pw_digest )
verify that a given passphrase matches its hashed version .