<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 中加盐和散列密码

      Salt and hash a password in Python(在 Python 中加盐和散列密码)

          <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 中加盐和散列密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)

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

                  <legend id='bhI8E'><style id='bhI8E'><dir id='bhI8E'><q id='bhI8E'></q></dir></style></legend>
                    <tbody id='bhI8E'></tbody>
                    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>