Masonite provides secure hashing for storing user passwords or other data. Bcrypt and Argon2 protocols can be used with Masonite (default is Bcrypt).
Hashing configuration is located at config/application.py
file. In this file, you can configure which protocol to use.
You can use the Hash
facade to easily hash a string (e.g. a password):
Note that you can return a hash as bytes with:
To check that a plain-text string corresponds to a given hash you can do:
You can determine if the work factor used by the hashing protocol has changed since the string was hashed using needs_rehash
:
You can change hashing protocol configuration on the fly for all Hash methods:
You can also change protocol on the fly: