<small id='MqerE'></small><noframes id='MqerE'>

<i id='MqerE'><tr id='MqerE'><dt id='MqerE'><q id='MqerE'><span id='MqerE'><b id='MqerE'><form id='MqerE'><ins id='MqerE'></ins><ul id='MqerE'></ul><sub id='MqerE'></sub></form><legend id='MqerE'></legend><bdo id='MqerE'><pre id='MqerE'><center id='MqerE'></center></pre></bdo></b><th id='MqerE'></th></span></q></dt></tr></i><div id='MqerE'><tfoot id='MqerE'></tfoot><dl id='MqerE'><fieldset id='MqerE'></fieldset></dl></div>
<legend id='MqerE'><style id='MqerE'><dir id='MqerE'><q id='MqerE'></q></dir></style></legend>

      <bdo id='MqerE'></bdo><ul id='MqerE'></ul>
    1. <tfoot id='MqerE'></tfoot>

      在 Python 中加盐和散列密码

      时间:2023-09-28

          <bdo id='eeXFP'></bdo><ul id='eeXFP'></ul>
          1. <small id='eeXFP'></small><noframes id='eeXFP'>

            <i id='eeXFP'><tr id='eeXFP'><dt id='eeXFP'><q id='eeXFP'><span id='eeXFP'><b id='eeXFP'><form id='eeXFP'><ins id='eeXFP'></ins><ul id='eeXFP'></ul><sub id='eeXFP'></sub></form><legend id='eeXFP'></legend><bdo id='eeXFP'><pre id='eeXFP'><center id='eeXFP'></center></pre></bdo></b><th id='eeXFP'></th></span></q></dt></tr></i><div id='eeXFP'><tfoot id='eeXFP'></tfoot><dl id='eeXFP'><fieldset id='eeXFP'></fieldset></dl></div>
              <tbody id='eeXFP'></tbody>
            <legend id='eeXFP'><style id='eeXFP'><dir id='eeXFP'><q id='eeXFP'></q></dir></style></legend>
          2. <tfoot id='eeXFP'></tfoot>

              • 本文介绍了在 Python 中加盐和散列密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                This code is supposed to hash a password with a salt. The salt and hashed password are being saved in the database. The password itself is not.

                Given the sensitive nature of the operation, I wanted to make sure everything was kosher.

                import hashlib
                import base64
                import uuid
                
                password = 'test_password'
                salt     = base64.urlsafe_b64encode(uuid.uuid4().bytes)
                
                
                t_sha = hashlib.sha512()
                t_sha.update(password+salt)
                hashed_password =  base64.urlsafe_b64encode(t_sha.digest())
                

                解决方案

                EDIT: This answer is wrong. A single iteration of SHA512 is fast, which makes it inappropriate for use as a password hashing function. Use one of the other answers here instead.


                Looks fine by me. However, I'm pretty sure you don't actually need base64. You could just do this:

                import hashlib, uuid
                salt = uuid.uuid4().hex
                hashed_password = hashlib.sha512(password + salt).hexdigest()
                

                If it doesn't create difficulties, you can get slightly more efficient storage in your database by storing the salt and hashed password as raw bytes rather than hex strings. To do so, replace hex with bytes and hexdigest with digest.

                这篇关于在 Python 中加盐和散列密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:获取隐藏密码输入 下一篇:验证密码 - Python

                相关文章

              • <tfoot id='bhI8E'></tfoot>

                <legend id='bhI8E'><style id='bhI8E'><dir id='bhI8E'><q id='bhI8E'></q></dir></style></legend>
                1. <small id='bhI8E'></small><noframes id='bhI8E'>

                  <i id='bhI8E'><tr id='bhI8E'><dt id='bhI8E'><q id='bhI8E'><span id='bhI8E'><b id='bhI8E'><form id='bhI8E'><ins id='bhI8E'></ins><ul id='bhI8E'></ul><sub id='bhI8E'></sub></form><legend id='bhI8E'></legend><bdo id='bhI8E'><pre id='bhI8E'><center id='bhI8E'></center></pre></bdo></b><th id='bhI8E'></th></span></q></dt></tr></i><div id='bhI8E'><tfoot id='bhI8E'></tfoot><dl id='bhI8E'><fieldset id='bhI8E'></fieldset></dl></div>
                    <bdo id='bhI8E'></bdo><ul id='bhI8E'></ul>