-2
\$\begingroup\$

This code snippet implements password hashing for safe storage. It uses Pbkdf2 for the hashing algorithm. The method hash_password() is used to hash and salt a password. The method verify() is used to check whether a password matches a hash.

Initial setup:

pip install pbkdf2

Code:

from pbkdf2 import crypt

def hash_password(password):
    return crypt(password)

def verify(pw_hash, password):
    if pw_hash == crypt(password, pw_hash):
        return True
    else:
        return False

def main():
    pw_hash = hash_password('s3cr3t')
    print(pw_hash)
    print(verify(pw_hash, 's3cr3t'))
    print(verify(pw_hash, 's3cr4t'))
    return None

if __name__ == '__main__':
    main()

1- Do you think the implementation of hash_password is up-to-date and secure?

2- Do you think the implementation of verify is up-to-date and secure?

3- Would you make any other changes to this code snippet?

4- Did you use any additional resources while checking the code? If yes, please provide a link or description of your resource

\$\endgroup\$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.