Mixin that adds useful password methods to your Python objects
Project description
Password Mixin
Mixin that add some useful methods to ORM objects
Compatible with Python 3.5 >= 3.9
Install
pip install password-mixin
Setup
first create your objects (of ORM model) and add a __hash_secret__
meta field.
Assign your application's secret value to __hash_secret__
.
from password_mixin import PasswordMixin
from sqlalchemy import Model # or Django , Flask-Sqlalchemy... etc.
class UserModel(OrmModel, PasswordMixon):
password = Column(String()) # you must have a `password`.
# Now create a meta field to define the secret used to create the salt, for example:
__hash_secret__ = "your-app-secret"
Usage
The password is saved as the following: "<salt>:<hash>"
Password Hashing
from password_mixin import PasswordAttributeError
try:
user = UserModel()
user.password = "wizard123"
user.hash_password() # password is now 31616263313233:7ac5cf88e8c9d262b49af168d9c30e47f2945cc9c207f20af0a39f09aa04595e
# Now you can save your user to your db etc.
except PasswordAttributeError:
# handle no password attribute
Validating Passwords
from password_mixin import PasswordMatchError
try:
user.check_password("wizard111")
except PasswordMatchError:
# handle passwords don't match
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
password-mixin-0.1.0.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for password_mixin-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9437aa76605d26c6d4a7d6f0d2002a08d7ab03b5f1cee9bc84e609145ad84302 |
|
MD5 | 35abee3543a725df94f3a0855d7f396d |
|
BLAKE2b-256 | 4337cbf910688dfde7ba7ee221f8b2d3f45531a90b6a4bd099d2b7deaad944cb |