What I am trying to do:
- Create a database table of 2 most recently used passwords (not including current).
What have I discovered so far?
- I have discovered the
check_password('123')
function- To my knowledge, this compares newly entered password to the current password before running
User.set_password()
- To my knowledge, this compares newly entered password to the current password before running
- I have created a table to store a username with the two previously used (not including current) passwords.
- I have discovered two different hash numbers
- User.get_session_auth_hash()
- Not sure if this is used for the password hashing?
- User.set_password.hash()
- Again, not sure if this is used for the password hashing?
- User.get_session_auth_hash()
My Issue:
In my python shell (under my project), I use User.set_password()
and set the same current password after running User.password
. Then when I run User.password
again and see that there is a different hash.
How do I save the previous password hashing method and re-use it to re-hash the password in order to compare it to the previously hashed password??
Example of password hashing with the same password
u = User.objects.get(username='username') # set user object
u.password # display current hashed password (password is set to '123')
# pbkdf2_sha256$24000$2lTIbv4a3deG$ElefaaF0aaFh6y50ENNT2pCNQKpoNvYBQ1nZojz8sUg=
u.get_session_auth_hash()
# 8ad1d1d3ac6d442b241f79d447a01ef561960ea4
u.set_password.__hash__()
# -123 (not really, just not sure if safe to post)
u.set_password('123')
# pbkdf2_sha256$24000$VVnXSQdHAak4$FJv3SH/m9jkBcUXAuxJbm0wyhjI+3JHccF7+D2s4qvs=
u.get_session_auth_hash()
# 8416cf2da88c2905862a93464317d779cf938211
u.set_password.__hash__()
# -123 (has not changed after password change)
This is just me running my commands in the proposed shell. I can only imagine there's random salting going on with the hashing. Just figured this might be useful.
My research amongst this sight brought me to this post:
How to implement password change form in django 1.9
Research Update
I am assuming the session_auth_hash
is being used in the hashing. I was starting to think maybe it was insecure to store this value in my database, but I can only assume that it is already stored somewhere because Django needs to use it to hash the entered password (when logging in) to verify it's the same password... I feel I just need to break down the set_password()
function..
Final Thoughts
Are there potential security issues?
To possibly answer my own question: If storing the salt is a bad idea, then so would storing the hashed password from Django. If someone has gained access to my DB, they'll be able to find the salt from the hashed password already stored in the DB anyway. I don't see too much of a difference other than separating the salt for a would be attacker who could do it themselves.