Advertisement
163

Generate Password Bookmarklet

163
Apr 21st, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. javascript:(function()%20{var%20tmp='';var%20str='23456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ';var%20len=str.length;for(var%20i=0;i<10;i++){tmp+=str[Math.floor(Math.random()*len)];}prompt('Your%20randomly%20generated%20password%20is:',tmp);})()
  2.  
  3. javascript:(function(){var%20PP={chars:['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'],defaultLength:32,testId:'tests-taym92CiEMHGiNRIO1dLasngy6MQaHHD',getCharacterCounts:function(s){var%20counts=[];for(var%20i=0;i<s.length;i++){counts[s.charAt(i)]=counts[s.charAt(i)]+1||1;}return%20counts;},printCharacterCounts:function(o){var%20text='';for(var%20i=0;i<this.chars.length;i++){text+=this.chars[i]+':%20'+o[this.chars[i]]+'\n';}this.printTest('character%20counts',text);},printTest:function(title,text){var%20tests=document.getElementById(this.testId);var%20header=document.createElement('h1');header.appendChild(document.createTextNode('Test:%20'+title));tests.appendChild(header);var%20textNode=document.createTextNode(text);var%20code=document.createElement('code');code.appendChild(textNode);var%20pre=document.createElement('pre');pre.appendChild(code);tests.appendChild(pre);},getRandom:function(){var%20max=this.chars.length;var%20random=Math.random();random=random+1;random=random*max;random=random-max;random=Math.floor(random);return%20random;},getRandoms:function(n){var%20randoms;for(var%20i=0;i<n;i++){randoms[i]=this.getRandom();}return%20randoms;},getRandomCharacter:function(){return%20this.chars[this.getRandom()];},getRandomString:function(n){var%20string='';for(var%20i=0;i<n;i++){string+=this.getRandomCharacter();}return%20string;},newPassword:function(n){return%20this.getRandomString(n);},toString:function(){return%20this.newPassword(this.defaultLength);},isTestPage:function(){if(document.getElementById(this.testId)){return%20true;}return%20false;},runTests:function(){for(var%20i=0;i<100;i++){this.printTest('length%20'+i,this.getRandomString(i));}var%20chars=this.getRandomString(10000);this.printCharacterCounts(this.getCharacterCounts(chars));chars='';for(var%20i=0;i<100;i++){chars+=this.getRandomString(100);}this.printCharacterCounts(this.getCharacterCounts(chars));},removeSinglePassword:function(elem){window.onclick=this.oc;elem.parentNode.removeChild(elem);document.body.style.position=this.body_position||'';},showSinglePassword:function(){var%20passwordContainerId='pb-'+this.testId;var%20passwordId=passwordContainerId+'-pw';var%20r=document.getElementById(passwordContainerId);if(r){this.removeSinglePassword(r);}this.body_position=document.body.style.position;document.body.style.position='relative';document.body.style.top='53px';var%20d=document.createElement('iframe');d.setAttribute('name',passwordContainerId);d.setAttribute('id',passwordContainerId);d.setAttribute('scrolling','no');d.setAttribute('frameborder',0);d.setAttribute('style','z-index:2147483647;%20position:fixed;%20height:53px;%20width:100%;%20top:0px;%20left:0px;%20border-bottom:3px%20solid%20#000;%20background-color:#fff;%20margin:0;%20padding:0;%20font-family:Helvetica,Arial;');document.body.appendChild(d);window[passwordContainerId].document.write('<html><body%20style=\'text-align:center;%20padding:8px;%20margin:0;\'><p%20id='+passwordId+'%20style=\'background-color:%20#fff;%20color:%20#000;%20margin:%200px%20auto;%20padding:8px;%20display:inline-block;%20font-size:18px;\'>'+this+'</p></body></html>');this.oc=window.onclick;var%20parent=this;window[passwordContainerId].onclick=window.onclick=function(e){if(parent.oc){parent.oc();}var%20t=e.target;if(!(t&&t.id===passwordId)){parent.removeSinglePassword(d);}};},setup:function(id){var%20parent=this;this.testId=id||this.testId;if(this.isTestPage()){window.setTimeout(function(){parent.runTests();parent.showSinglePassword();},1000);}else{this.showSinglePassword();}}};PP.setup();})();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement