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

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

      1. <tfoot id='t4RZH'></tfoot>

          <bdo id='t4RZH'></bdo><ul id='t4RZH'></ul>
      2. 高质量、简单的随机密码生成器

        High quality, simple random password generator(高质量、简单的随机密码生成器)
        <legend id='MyEDa'><style id='MyEDa'><dir id='MyEDa'><q id='MyEDa'></q></dir></style></legend>

        1. <small id='MyEDa'></small><noframes id='MyEDa'>

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

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

                    <tbody id='MyEDa'></tbody>
                  本文介绍了高质量、简单的随机密码生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有兴趣创建一个非常简单、高质量(加密)的随机密码生成器.有没有更好的方法来做到这一点?

                  I'm interested in creating a very simple, high (cryptographic) quality random password generator. Is there a better way to do this?

                  import os, random, string
                  
                  length = 13
                  chars = string.ascii_letters + string.digits + '!@#$%^&*()'
                  random.seed = (os.urandom(1024))
                  
                  print ''.join(random.choice(chars) for i in range(length))
                  

                  推荐答案

                  密码的难点在于让它们足够强大并且仍然能够记住它们.如果密码不应该被人类记住,那么它就不是真正的密码.

                  The difficult thing with passwords is to make them strong enough and still be able to remember them. If the password is not meant to be remembered by a human being, then it is not really a password.

                  您使用 Python 的 os.urandom():这很好.对于任何实际目的(甚至密码学),os.urandom() 的输出与真正的 alea 没有区别.然后你将它用作 random 中的种子,这不太好:它是一个非加密 PRNG,它的输出可能会表现出一些不会在统计测量工具中注册的结构,但可能是被聪明的攻击者利用.您应该一直使用 os.urandom().为简单起见:选择长度为 64 的字母表,例如字母(大写和小写)、数字和两个额外的标点符号(例如+"和/").然后,对于每个密码字符,从 os.urandom() 中获取一个字节,以 64 为模减少值(这是无偏的,因为 64 除以 256)并将结果用作 chars 中的索引 数组.

                  You use Python's os.urandom(): that's good. For any practical purpose (even cryptography), the output of os.urandom() is indistinguishable from true alea. Then you use it as seed in random, which is less good: that one is a non-cryptographic PRNG, and its output may exhibit some structure which will not register in a statistical measurement tool, but might be exploited by an intelligent attacker. You should work with os.urandom() all along. To make things simple: choose an alphabet of length 64, e.g. letters (uppercase and lowercase), digits, and two extra punctuation characters (such as '+' and '/'). Then, for each password character, get one byte from os.urandom(), reduce the value modulo 64 (this is unbiased because 64 divides 256) and use the result as index in your chars array.

                  对于长度为 64 的字母表,每个字符的熵为 6 位(因为 26 = 64).因此,对于 13 个字符,您将获得 78 位的熵.这最终并不是在所有情况下都很强大,但已经非常强大(它可能会被以数月和数十亿美元计算的预算击败,而不仅仅是数百万).

                  With an alphabet of length 64, you get 6 bits of entropy per character (because 26 = 64). Thus, with 13 characters, you get 78 bits of entropy. This is not ultimately strong in all cases, but already very strong (it could be defeated with a budget which will be counted in months and billions of dollars, not mere millions).

                  这篇关于高质量、简单的随机密码生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 数据框制作线图?)
                  <i id='gCPwT'><tr id='gCPwT'><dt id='gCPwT'><q id='gCPwT'><span id='gCPwT'><b id='gCPwT'><form id='gCPwT'><ins id='gCPwT'></ins><ul id='gCPwT'></ul><sub id='gCPwT'></sub></form><legend id='gCPwT'></legend><bdo id='gCPwT'><pre id='gCPwT'><center id='gCPwT'></center></pre></bdo></b><th id='gCPwT'></th></span></q></dt></tr></i><div id='gCPwT'><tfoot id='gCPwT'></tfoot><dl id='gCPwT'><fieldset id='gCPwT'></fieldset></dl></div>
                  • <small id='gCPwT'></small><noframes id='gCPwT'>

                      <bdo id='gCPwT'></bdo><ul id='gCPwT'></ul>
                      <tfoot id='gCPwT'></tfoot>
                      <legend id='gCPwT'><style id='gCPwT'><dir id='gCPwT'><q id='gCPwT'></q></dir></style></legend>

                          <tbody id='gCPwT'></tbody>