テストアカウントとかで簡単に使えるPython製のパスワードジェネレータです。password_hashとかpassword_verifyで確認してみて下さい。
事前準備
pip install bcrypt
コード
passward_hash.py
import bcrypt
def check_password(pw: bytes, h_pw: bytes) -> bool:
if bcrypt.checkpw(pw, h_pw):
return True
else:
return False
def get_password(pw: bytes) -> bytes:
salt = bcrypt.gensalt(rounds=10, prefix=b'2b')
return bcrypt.hashpw(pw, salt=salt)
def run():
pw = input("ハッシュ化以前のパスワードを入力して下さい。").encode('utf-8')
hash_pw = get_password(pw=pw)
result = check_password(pw=pw, h_pw=hash_pw)
if result:
print("検証完了!", end='')
print(f"\npure: {pw}")
print(f"hashed: {hash_pw}")
else:
print("検証失敗!")
while True:
run()
実行結果
何回か試しに入れてみると出力する結果が毎回違っているので、あれ、これアカンやん!って思ったのですが、なんかOKみたいです。よー分からん!!