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生成具有特定字母数量的随机密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)

                        <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'>