Based on my current Django app settings, is there a function or a snippet that allows me to view the encrypted password, given a raw string? I am testing some functionality and this would be useful for me.
I am looking for something like:
password = encrypt_raw_password("abcdef")
There is a small util function just for that: make_password.
You can make use of Django auth hashers:
from django.contrib.auth.hashers import make_password
password = make_password('somepass@123')
The version of Django should be 1.8 and above. I have tested in the latest version Django 3+
An update on this question since the previous answer does not seem to be supported.
import crypt
# To encrypt the password. This creates a password hash with a random salt.
password_hash = crypt.crypt(password)
# To check the password.
valid_password = crypt.crypt(cleartext, password_hash) == password_hash
Source: https://docs.python.org/2/library/crypt.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With