Reputation: 409
I have Device
model that has a field named token
that stores a pbkdf2_sha256 hashed string.
from django.contrib.auth.hashers import make_password
from django.models import Model, CharField
class Device(Model):
name = CharField(max_length=200)
token = CharField(unique=True, max_length=128)
def save(self,*args,**kwargs):
self.token = make_password(self.token)
super().save(*args,**kwargs)
for example I have a Device object that it's token is hashed value of ABCD
. now question is if I get ABCD
from user as raw token, how i can find it's device from database? I tried this:
I hashed the ABCD
that I got from user with make_password
, but the new hashed value wasn't as same as the old one that was in db.
also I know that I can get device id from user and then check if user's entered token is same with check_password
method. but I want only get token from user not device id and token.
Upvotes: 0
Views: 218
Reputation: 73
I don't think "pbkdf2_sha256" is the right algorithm for this case as even to check if password is correct, "check_password" doesn't do a simple string comparison. You need a symetrical algo I think or a simple hash algo for which a simple string comparison will work
Upvotes: 1