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

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

        Python 从数据库中存储和检索密码的最安全方法

        Python#39;s safest method to store and retrieve passwords from a database(Python 从数据库中存储和检索密码的最安全方法)
      3. <legend id='Mw4Up'><style id='Mw4Up'><dir id='Mw4Up'><q id='Mw4Up'></q></dir></style></legend>

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

              <bdo id='Mw4Up'></bdo><ul id='Mw4Up'></ul>

                <tbody id='Mw4Up'></tbody>
                <tfoot id='Mw4Up'></tfoot>
                <i id='Mw4Up'><tr id='Mw4Up'><dt id='Mw4Up'><q id='Mw4Up'><span id='Mw4Up'><b id='Mw4Up'><form id='Mw4Up'><ins id='Mw4Up'></ins><ul id='Mw4Up'></ul><sub id='Mw4Up'></sub></form><legend id='Mw4Up'></legend><bdo id='Mw4Up'><pre id='Mw4Up'><center id='Mw4Up'></center></pre></bdo></b><th id='Mw4Up'></th></span></q></dt></tr></i><div id='Mw4Up'><tfoot id='Mw4Up'></tfoot><dl id='Mw4Up'><fieldset id='Mw4Up'></fieldset></dl></div>
                • 本文介绍了Python 从数据库中存储和检索密码的最安全方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Looking to store usernames and passwords in a database, and am wondering what the safest way to do so is. I know I have to use a salt somewhere, but am not sure how to generate it securely or how to apply it to encrypt the password. Some sample Python code would be greatly appreciated. Thanks.

                  解决方案

                  Store the password+salt as a hash and the salt. Take a look at how Django does it: basic docs and source. In the db they store <type of hash>$<salt>$<hash> in a single char field. You can also store the three parts in separate fields.

                  The function to set the password:

                  def set_password(self, raw_password):
                      import random
                      algo = 'sha1'
                      salt = get_hexdigest(algo, str(random.random()), str(random.random()))[:5]
                      hsh = get_hexdigest(algo, salt, raw_password)
                      self.password = '%s$%s$%s' % (algo, salt, hsh)
                  

                  The get_hexdigest is just a thin wrapper around some hashing algorithms. You can use hashlib for that. Something like hashlib.sha1('%s%s' % (salt, hash)).hexdigest()

                  And the function to check the password:

                  def check_password(raw_password, enc_password):
                      """
                      Returns a boolean of whether the raw_password was correct. Handles
                      encryption formats behind the scenes.
                      """
                      algo, salt, hsh = enc_password.split('$')
                      return hsh == get_hexdigest(algo, salt, raw_password)
                  

                  这篇关于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 数据框制作线图?)
                  <legend id='uNaUu'><style id='uNaUu'><dir id='uNaUu'><q id='uNaUu'></q></dir></style></legend>
                      • <bdo id='uNaUu'></bdo><ul id='uNaUu'></ul>

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

                          • <small id='uNaUu'></small><noframes id='uNaUu'>