forked from GoogleCloudPlatform/bank-of-anthos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from splunk/Spans
NEw hash functionality replacing the slow bcrypt
- Loading branch information
Showing
9 changed files
with
118 additions
and
46 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,3 +235,4 @@ spec: | |
- key: jwtRS256.key.pub | ||
path: publickey | ||
secretName: jwt-key | ||
|
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
import hashlib | ||
import os | ||
import sys | ||
|
||
# Function to hash a password using PBKDF2 | ||
def hash_password_pbkdf2(password: str) -> str: | ||
# Generate a new salt | ||
salt = os.urandom(16) | ||
# Hash the password using PBKDF2 with SHA-256 | ||
hashed = hashlib.pbkdf2_hmac('sha256', password.encode('utf-8'), salt, 10000) | ||
# Return the salt and hashed password as a combined string | ||
return salt.hex() + "|" + hashed.hex() | ||
|
||
# Main function for the command-line interface | ||
def main(): | ||
if len(sys.argv) != 2: | ||
print("Usage: python hash.py <password>") | ||
sys.exit(1) | ||
|
||
password = sys.argv[1] | ||
|
||
# Hash the password using PBKDF2 | ||
pbkdf2_hashed_password = hash_password_pbkdf2(password) | ||
print(f"PBKDF2 Hashed Password: {pbkdf2_hashed_password}") | ||
|
||
if __name__ == "__main__": | ||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import hashlib | ||
|
||
# Function to verify the password using PBKDF2 | ||
def verify_password(password: str, stored_hash: str) -> bool: | ||
# One-liner to verify the password with PBKDF2 | ||
return hashlib.pbkdf2_hmac('sha256', password.encode('utf-8'), bytes.fromhex(stored_hash.split('|')[0]), 10000).hex() == stored_hash.split(':')[1] | ||
|
||
# Main function for testing the condition | ||
def main(): | ||
# Known hash generated by the hashing function (format: salt:hash) | ||
stored_hash = input("Enter the known hash (format: salt:hash): ") | ||
|
||
# Input password to be tested | ||
password = input("Enter the password to verify: ") | ||
|
||
# Verifying the password | ||
if not verify_password(password, stored_hash): | ||
print("Password is invalid!") | ||
else: | ||
print("Password is valid!") | ||
|
||
if __name__ == "__main__": | ||
main() |