Refonte authentification en crypté
This commit is contained in:
26
bcrypt_check.py
Normal file
26
bcrypt_check.py
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/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())
|
||||
Reference in New Issue
Block a user