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

        <legend id='bLVmy'><style id='bLVmy'><dir id='bLVmy'><q id='bLVmy'></q></dir></style></legend>
        <tfoot id='bLVmy'></tfoot>

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

          <bdo id='bLVmy'></bdo><ul id='bLVmy'></ul>
      2. Javascript生成具有特定字母数量的随机密码

        Javascript to generate random password with specific number of letters(Javascript生成具有特定字母数量的随机密码)
        • <small id='4xGUL'></small><noframes id='4xGUL'>

          <legend id='4xGUL'><style id='4xGUL'><dir id='4xGUL'><q id='4xGUL'></q></dir></style></legend>

              <tfoot id='4xGUL'></tfoot>
              • <bdo id='4xGUL'></bdo><ul id='4xGUL'></ul>
                    <tbody id='4xGUL'></tbody>
                  <i id='4xGUL'><tr id='4xGUL'><dt id='4xGUL'><q id='4xGUL'><span id='4xGUL'><b id='4xGUL'><form id='4xGUL'><ins id='4xGUL'></ins><ul id='4xGUL'></ul><sub id='4xGUL'></sub></form><legend id='4xGUL'></legend><bdo id='4xGUL'><pre id='4xGUL'><center id='4xGUL'></center></pre></bdo></b><th id='4xGUL'></th></span></q></dt></tr></i><div id='4xGUL'><tfoot id='4xGUL'></tfoot><dl id='4xGUL'><fieldset id='4xGUL'></fieldset></dl></div>
                1. 本文介绍了Javascript生成具有特定字母数量的随机密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在网页中,在客户端,用 Javascript 生成密码.密码应该使用字母和数字,也许是一些符号.如何安全地在 Javascript 中生成密码?

                  I want to generate a password in a web page, on the client side, in Javascript. The password should use letters and numbers, perhaps some symbols. How can I generate a password in Javascript securely?

                  推荐答案

                  由于密码需要不可预测,因此需要由种子良好的加密 PRNG 生成.Math.random 通常不安全.

                  Since a password needs to be unpredictable, it needs to be generated by a well seeded crypto PRNG. Math.random is usually not secure.

                  现代浏览器(至少是当前版本的 Firefox 和 Chrome)支持生成安全随机值的 window.crypto.getRandomValues.

                  Modern browsers (At least the current versions of Firefox and Chrome) support window.crypto.getRandomValues which generates secure random values.

                  基于 Presto 的 Opera 不支持它,但它的 Math.random 是安全的.但是既然 Opera 已经死了,那么回退应该不再是必要的了.

                  Presto based Opera doesn't support it, but its Math.random is secure. But since Opera has died, the fallback shouldn't be necessary anymore.

                  function randomString(length)
                  {
                      var charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
                      var i;
                      var result = "";
                      var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
                      if(window.crypto && window.crypto.getRandomValues)
                      {
                          values = new Uint32Array(length);
                          window.crypto.getRandomValues(values);
                          for(i=0; i<length; i++)
                          {
                              result += charset[values[i] % charset.length];
                          }
                          return result;
                      }
                      else if(isOpera)//Opera's Math.random is secure, see http://lists.w3.org/Archives/Public/public-webcrypto/2013Jan/0063.html
                      {
                          for(i=0; i<length; i++)
                          {
                              result += charset[Math.floor(Math.random()*charset.length)];
                          }
                          return result;
                      }
                      else throw new Error("Your browser sucks and can't generate secure random numbers");
                  }
                  
                  alert(randomString(10))
                  

                  http://jsfiddle.net/ebbpa/

                  这篇关于Javascript生成具有特定字母数量的随机密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Toggle HTML radio button by clicking its label(通过单击标签来切换 HTML 单选按钮)
                  Javascript how to change radio button label text?(Javascript如何更改单选按钮标签文本?)
                  JavaScript radio button confirmation(JavaScript 单选按钮确认)
                  How can I automatically select specific radio buttons with Greasemonkey?(如何使用 Greasemonkey 自动选择特定的单选按钮?)
                  AngularJs. Is it possible to deselect HTML “radio” input by click?(AngularJs.是否可以通过单击取消选择 HTML“收音机输入?)
                  Checking Value of Radio Button Group via JavaScript?(通过 JavaScript 检查单选按钮组的值?)

                        <tbody id='3FhE6'></tbody>
                        <tfoot id='3FhE6'></tfoot>
                        <i id='3FhE6'><tr id='3FhE6'><dt id='3FhE6'><q id='3FhE6'><span id='3FhE6'><b id='3FhE6'><form id='3FhE6'><ins id='3FhE6'></ins><ul id='3FhE6'></ul><sub id='3FhE6'></sub></form><legend id='3FhE6'></legend><bdo id='3FhE6'><pre id='3FhE6'><center id='3FhE6'></center></pre></bdo></b><th id='3FhE6'></th></span></q></dt></tr></i><div id='3FhE6'><tfoot id='3FhE6'></tfoot><dl id='3FhE6'><fieldset id='3FhE6'></fieldset></dl></div>
                        <legend id='3FhE6'><style id='3FhE6'><dir id='3FhE6'><q id='3FhE6'></q></dir></style></legend>
                            <bdo id='3FhE6'></bdo><ul id='3FhE6'></ul>
                          • <small id='3FhE6'></small><noframes id='3FhE6'>