@madpilot makes

Password Generating Bookmarklet

Some how I managed to get lumped with the un-enviable task of creating email accounts for clients at Bam Creative – we currently have to use an archaic web interface and it takes forever. One of the many things that annoyed me about the system, is it can’t generate passwords for you, so I whipped up this little bookmarklet that will generate an eight character password made up of upper and lowercase letters and numbers. It adds a small div to the very top of the page you are viewing. Clicking the password makes it disappear again.

Drag the following link into you bookmarks. Click it now to see it work!

[Password generator][2]

Known issues:

  • It doesn’t play nice with frames, it will throw a JavaScript error.
  • Clicking the link in IE doesn’t make it disappear.

The raw code:

<li class="li1">
  <div class="de1">
    <span class="kw1">for</span><span class="br0">(</span>i=<span class="nu0"></span>; i < <span class="nu0">8; i++<span class="br0">)</span><span class="br0">{</span></div> </li> 
    
    <li class="li1">
      <div class="de1">
        <ins class="in"> </ins> <span class="kw1">switch</span><span class="br0">(</span>Math.<span class="me1">round</span><span class="br0">(</span>Math.<span class="me1">random</span><span class="br0">(</span><span class="br0">)</span> * <span class="nu0">2</span><span class="br0">)</span><span class="br0">)</span> <span class="br0">{</span>
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        <ins class="in"> </ins> <ins class="in"> </ins> <span class="kw1">case</span> <span class="nu0"></span>:
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        <ins class="in"> </ins> <ins class="in"> </ins> <ins class="in"> </ins> passwd += String.<span class="me1">fromCharCode</span><span class="br0">(</span>Math.<span class="me1">round</span><span class="br0">(</span>Math.<span class="me1">random</span><span class="br0">(</span><span class="br0">)</span> * <span class="nu0">25</span><span class="br0">)</span> + <span class="nu0">65</span><span class="br0">)</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        <ins class="in"> </ins> <ins class="in"> </ins> <ins class="in"> </ins> <span class="kw1">break</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        <ins class="in"> </ins> <ins class="in"> </ins> <span class="kw1">case</span> <span class="nu0">1</span>:
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        <ins class="in"> </ins> <ins class="in"> </ins> <ins class="in"> </ins> passwd += String.<span class="me1">fromCharCode</span><span class="br0">(</span>Math.<span class="me1">round</span><span class="br0">(</span>Math.<span class="me1">random</span><span class="br0">(</span><span class="br0">)</span> * <span class="nu0">25</span><span class="br0">)</span> + <span class="nu0">97</span><span class="br0">)</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        <ins class="in"> </ins> <ins class="in"> </ins> <ins class="in"> </ins> <span class="kw1">break</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        <ins class="in"> </ins> <ins class="in"> </ins> <span class="kw1">case</span> <span class="nu0">2</span>:
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        <ins class="in"> </ins> <ins class="in"> </ins> <ins class="in"> </ins> passwd += Math.<span class="me1">round</span><span class="br0">(</span>Math.<span class="me1">random</span><span class="br0">(</span><span class="br0">)</span> * <span class="nu0">9</span><span class="br0">)</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        <ins class="in"> </ins> <ins class="in"> </ins> <ins class="in"> </ins> <span class="kw1">break</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        <ins class="in"> </ins> <span class="br0">}</span>
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        <span class="br0">}</span>
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        <ins class="in"> </ins>
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        <span class="kw2">var</span> pDiv=document.<span class="me1">createElement</span><span class="br0">(</span><span class="st0">&#8216;div&#8217;</span><span class="br0">)</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        pDiv.<span class="me1">setAttribute</span><span class="br0">(</span><span class="st0">&#8216;style&#8217;</span>,<span class="st0">&#8216;postion:absolute; top:0px; left:0px; border: 1px solid black; background-color: grey; text-align: center;&#8217;</span><span class="br0">)</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1" />
    </li>
    <li class="li1">
      <div class="de1">
        <span class="kw2">var</span> pClose=document.<span class="me1">createElement</span><span class="br0">(</span><span class="st0">&#8216;a&#8217;</span><span class="br0">)</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        pClose.<span class="me1">setAttribute</span><span class="br0">(</span><span class="st0">&#8216;href&#8217;</span>,<span class="st0">&#8216;#&#8217;</span><span class="br0">)</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        pClose.<span class="me1">setAttribute</span><span class="br0">(</span><span class="st0">&#8216;style&#8217;</span>,<span class="st0">&#8216;color: white&#8217;</span><span class="br0">)</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        pClose.<span class="me1">setAttribute</span><span class="br0">(</span><span class="st0">&#8216;onclick&#8217;</span>,<span class="st0">&#8216;this.parentNode.parentNode.removeChild(this.parentNode);&#8217;</span><span class="br0">)</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        pClose.<span class="me1">appendChild</span><span class="br0">(</span>document.<span class="me1">createTextNode</span><span class="br0">(</span>passwd<span class="br0">)</span><span class="br0">)</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        pDiv.<span class="me1">appendChild</span><span class="br0">(</span>pClose<span class="br0">)</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        body = document.<span class="me1">getElementsByTagName</span><span class="br0">(</span><span class="st0">&#8216;body&#8217;</span><span class="br0">)</span>;
      </div>
    </li>
    
    <li class="li1">
      <div class="de1">
        body<span class="br0">[</span><span class="nu0"></span><span class="br0">]</span>.<span class="me1">insertBefore</span><span class="br0">(</span>pDiv,body<span class="br0">[</span><span class="nu0"></span><span class="br0">]</span>.<span class="me1">firstChild</span><span class="br0">)</span>;
      </div>
    </li></ol> </div> 
    
    <ul />

[2]: javascript:passwd=’’;for(i=0;i<8;i++){switch(Math.round(Math.random()*2)){case 0: passwd+=String.fromCharCode(Math.round(Math.random()*25)+65);break;case 1:passwd+=String.fromCharCode(Math.round(Math.random()*25)+97);break;case 2:passwd+=Math.round(Math.random() * 9);break;}}var pDiv=document.createElement(‘div’);pDiv.setAttribute(‘style’,‘postion:absolute;top:0px;left:0px;border:1px solid black;background-color:grey;text-align:center;’);var pClose=document.createElement(‘a’);pClose.setAttribute(‘href’,’#’);pClose.setAttribute(‘style’,‘color:white’);pClose.setAttribute(‘onclick’,’this.parentNode.parentNode.removeChild(this.parentNode);’);pClose.appendChild(document.createTextNode(passwd));pDiv.appendChild(pClose);body=document.getElementsByTagName(‘body’);body[0].insertBefore(pDiv,body[0].firstChild);void(null);