jeudi 13 août 2015

using uuid and bcrypt with django not generating unique values

building a uuid then hashing it with bcrypt ends up generating an object with the same value in auth_secret(uuid4() is not generating a unique value for each new instance) every time one is initialized. Here is the terminal output

>>> from quickstart.models import FarmUserAuthentication
>>> c = FarmUserAuthentication('as')
>>> d = FarmUserAuthentication('asdfs')
>>> c
<FarmUserAuthentication:  $2a$12$euUMcvhPwPsS7SQgiOVGNeWr792cq.tKONl9bTVjY3nvrxpczPqs6>
>>> d
<FarmUserAuthentication:  $2a$12$euUMcvhPwPsS7SQgiOVGNeWr792cq.tKONl9bTVjY3nvrxpczPqs6>

here is my code in models.py

class FarmUserAuthentication(models.Model):
    auth_id = models.CharField(primary_key = True, max_length = 10)
    hash = bcrypt.hashpw(str(uuid.UUID4()), bcrypt.gensalt())
    auth_secret = models.CharField(max_length=100, default= hash, editable=False)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire