Created
September 28, 2017 22:04
-
-
Save curtmack/f277811d1f17ffd6908464c9da458263 to your computer and use it in GitHub Desktop.
Command-line Python script for generating and testing BCrypt hashes. Requires the 'bcrypt' pip package.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import bcrypt | |
import sys | |
if len(sys.argv) < 4: | |
print ("Usage: " + sys.argv[0] + " {2a|2b} {workFactor} {password}") | |
else: | |
version = sys.argv[1].encode("ascii") | |
workFactor = int(sys.argv[2]) | |
password = sys.argv[3].encode("ascii") | |
hashed = bcrypt.hashpw(password, bcrypt.gensalt(workFactor, prefix=version)) | |
print(hashed .decode("ascii")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import bcrypt | |
import sys | |
if len(sys.argv) < 3: | |
print ("Usage: " + sys.argv[0] + " {password} {passwordHash}") | |
else: | |
password = sys.argv[1].encode("ascii") | |
hashed = sys.argv[2].encode("ascii") | |
if bcrypt.hashpw(password, hashed) == hashed: | |
print("Match") | |
else: | |
print("No match") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment