It is an implementation of authentication and authorization.
Bcrypt is a popular password storage algorithm that’s specifically designed for long-term password storage.
Install the bcrypt library. This can be done by running
pip install bcrypt
Run the python interpreter (python interactive shell)!!
import bcrypt
Bcrypt encrypts bytes type data, not str type. If we encode str type data, it becomes bytes(binary), and if we decode bytes data, it comes back to str type.
password = '1234'
hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
print(hashed_password)
b'$2b$12$YFs9rh.1LgJwZuf9ibyjpuLvBoCaGX0MzedFWF2Jo0zU3lMZurZ4a'
It shows the encrypted password.
type(hashed_password)
<class 'bytes'>
This is an one way encryption, which can not be decrypted.
Then, how to check the password?
new_password = '1234'
bcrypt.checkpw(new_password.encode('utf-8'),hashed_password)
True