Files
go-ctf/starpost/tests/password_hash_regression.py

31 lines
826 B
Python

#!/usr/bin/env python3
import sys
from pathlib import Path
from werkzeug.security import generate_password_hash
API_DIR = Path(__file__).resolve().parents[1] / "api"
sys.path.insert(0, str(API_DIR))
from passwords import hash_password, password_matches # noqa: E402
def main():
password = "correct horse battery staple"
current_hash = hash_password(password)
assert current_hash.startswith("pbkdf2:sha256:600000$")
assert password_matches(current_hash, password)
assert not password_matches(current_hash, password + "!")
legacy_hash = generate_password_hash(password, method="scrypt:32768:8:1")
assert password_matches(legacy_hash, password)
assert not password_matches(legacy_hash, password + "!")
print("password hash compatibility: ok")
if __name__ == "__main__":
main()