xxxxxxxxxx
import hashlib
password = "mysecretpassword"
# Create a SHA-256 hash object
hash_object = hashlib.sha256()
# Convert the password to bytes and hash it
hash_object.update(password.encode())
# Get the hex digest of the hash
hash_password = hash_object.hexdigest()
print(hash_password)
xxxxxxxxxx
from passlib.hash import sha256_crypt
password = sha256_crypt.encrypt("password")
password2 = sha256_crypt.encrypt("password")
print(password)
print(password2)
print(sha256_crypt.verify("password", password))
xxxxxxxxxx
# User's password without echoing
import maskpass # to hide the password
# masking the password, without using the mask key, the default masking is "*"
pwd = maskpass.askpass("password: " ,mask="")
if (pwd == 'nick'):
print('Welcome')
else:
print("Incorrect password")
xxxxxxxxxx
# Echoing password and masked with hashtag(#)
import maskpass # importing maskpass library
# prompt msg = Password and
# masking password with hashtag(#)
pwd = maskpass.askpass(prompt="Password:", mask="#")
print(pwd)