Skip to content

Dependency-Track: Password validator tool

from hashlib import sha512
import bcrypt

# Replace with the extracted hash from the database
# "$2a$14$anrervkk5mlGn6T1G1gOuef472etShqvA5VVTImQ2DES3HFozysXW" = admin123
stored_hash = "$2a$14$anrervkk5mlGn6T1G1gOuef472etShqvA5VVTImQ2DES3HFozysXW"

password = input("Enter password to verify: ")
prehash = sha512(password.encode()).hexdigest().encode()

# Verify password
if bcrypt.checkpw(prehash, stored_hash):
    print("Password is correct!")
else:
    print("Incorrect password.")

Example output:

py test_admin_password.sh
Enter password to verify: password123
Incorrect password.

py test_admin_password.sh
Enter password to verify: admin123
Password is correct!