【问题标题】:"double salting" a password with python [closed]用python“双重加盐”密码[关闭]
【发布时间】:2020-04-09 21:52:16
【问题描述】:

我想在 python 中创建一个“双盐”密码,它应该给出与下面的 php 代码相同的结果。

php代码:sha1($salt . sha1($salt . sha1($password)));

希望有人可以帮助我解决我的问题。

【问题讨论】:

  • 你可以一直撒盐直到奶牛回家,sha1 仍然无法安全地散列和存储密码。请改用password_hash() 并让他们更新密码。
  • @Alfred der Große 你有多少用户?
  • 大约5000个用户
  • 我不打算使用 sha1 作为主要哈希器,django 应该在登录后立即更新密码。
  • 还有什么问题?

标签: python php sha1


【解决方案1】:

您可以在这里申请functools.reduce():

from hashlib import sha1
from functools import reduce

result = reduce(lambda a, b: b + sha1(a.encode()).hexdigest(), (password, salt, salt, ''))

您还可以链接函数调用(效率会提高约 30%,但不会那么紧凑):

from hashlib import sha1

result = sha1((salt + sha1((salt + sha1(password.encode()).hexdigest()).encode()).hexdigest()).encode()).hexdigest()

【讨论】:

    猜你喜欢
    • 2012-07-05
    • 2010-10-15
    • 1970-01-01
    • 2010-09-19
    • 2015-10-08
    • 2011-11-27
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多