Not having much time to update the site regularly has been a bit of a problem. But sometimes I do manage to find a few spare minutes here and there to play around with tiny projects. Late last week, I was taking a look at my friend Alastair's blog http://www.lazyefficient.com/ where he had published a small post about a password generation service.

"I used to use http://www.goodpassword.com for generating random passwords for random accounts I created. However when I went there this morning I noticed that the site has gone to a Pay-For-Service model (rather than advertising). You only find this out after clicking the "Generate Password" button."
- lazyefficient.com

So, after taking a look at Alastair's password generator, I decided it'd be a fun little diversion to build my own. Not that I personally use anything like that, but it's more about the joy of coding for me.

Firstly, my design was based entirely on the quick look I had at Alastair's user interface, and functionality. I didn't even look at his inspiration before I started coding my solution. I wanted to keep it simple, keep it quick.

I kept a few design goals in my head as I started coding:

  • File size - keep it small as possible
  • Speed - Not really a problem considering the scope of the project.
    It would more likely have been difficult to make it run slowly.
  • Deployable - I wanted to be able to allow anybody to have a copy of this on any page they wanted.

These goals were all very achievable considering the scope of the project, so not much else to say about it. Well, except the deployability, but I'll talk about that later.

For now, here's an embedded version of the generator:

As you can see, the interface is not what you'd call complete, but it is functional.

To embed this in a web page, simply include this script:

<script type="text/javascript" src="http://supercalifrigginawesome.com/spwg.js"></script>

Then, where you want to include the form, just use the following script:

<script type="text/javascript">renderPWG();</script>

As I mentioned earlier, the deployablity of the script has a couple of problems:
It's not in it's own namespace, and will conflict with itself if the renderPWG() function is called more than once.
If I could be bothered spending more time on the project, I would have fixed these problems.

I'm sure there may be some other problems I haven't foreseen with the code, but that's okay. It was just a little time-waster, but if anybody would like me to finish off the few little problems I mentioned, leave me a comment.

As for my loosely defined design goals:

  • File Size - It's around 2.3KB, which is fine by me. I could have made it a bit smaller, but at the cost of readability I think...
  • Speed - Well, due to the small file-size, it seems to load fairly quickly, and the script itself doesn't require much time on the processor.
  • Deployable - I sort of got this achieved, but I wouldn't be happy to use it anywhere important for now. With the fixes I mentioned, it would be there... as is, I'd say I slightly missed the mark on this goal.
    That being said, it is deployable, and it will work, as long as there is nothing for it to conflict with. I'm still happy with the current result.

If you like either Alastair's or my password generator, feel free to leave a donation on Al's password generator page.

I haven't posted the code, it's pretty self explanatory. But if you'd like me to post it with some commentary I'd be happy to. Just let me know in the comments.