Salt Generation and open source software

后端 未结 6 1971
孤独总比滥情好
孤独总比滥情好 2020-11-22 07:37

As I understand it, the best practice for generating salts is to use some cryptic formula (or even magic constant) stored in your source code.

I\'m working on a proj

6条回答
  •  庸人自扰
    2020-11-22 08:22

    Use a random function generator to generate the salt, and store it in the database, make salt one per row, and store it in the database.

    I like how salt is generated in django-registration. Reference: http://bitbucket.org/ubernostrum/django-registration/src/tip/registration/models.py#cl-85

    salt = sha_constructor(str(random.random())).hexdigest()[:5]
    activation_key = sha_constructor(salt+user.username).hexdigest()
    return self.create(user=user,
               activation_key=activation_key)
    

    He uses a combination of sha generated by a random number and the username to generate a hash.

    Sha itself is well known for being strong and unbreakable. Add multiple dimensions to generate the salt itself, with random number, sha and the user specific component, you have unbreakable security!

提交回复
热议问题