27 lines
639 B
Python
27 lines
639 B
Python
#!/usr/bin/env python3
|
|
import sys, argparse, bcrypt
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("--hash", required=True)
|
|
ap.add_argument("--password-stdin", action="store_true")
|
|
args = ap.parse_args()
|
|
|
|
if not args.password_stdin:
|
|
print("ERR")
|
|
return 2
|
|
|
|
password = sys.stdin.read().rstrip("\r\n")
|
|
try:
|
|
ok = bcrypt.checkpw(password.encode("utf-8"),
|
|
args.hash.encode("ascii"))
|
|
except Exception:
|
|
print("ERR")
|
|
return 2
|
|
|
|
print("OK" if ok else "ERR")
|
|
return 0 if ok else 1
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|