3273756192_6008cde373_b This has been sitting in my queue for some time: almost four years ago (it’s incredible how time flies!) – amongst the first posts I’ve published on the blog – I’ve written a random password generator in Javascript which I’ve named YARPG (for “Yet Another Random Password Generator”). The advantages to using it are the same as they were back then:

  • Customizable (password length, types of characters included, etc)
  • Secure (it doesn’t communicate over the network, hence no need for SSL)
  • Fully reviewable (as opposed to server-based solutions, where you have to trust the server)

The only flaw it had (as pointed out by a commenter) was the fact that passwords didn’t always include all the characters you’ve selected (ie. the checkboxes represented “possible” not “mandatory” characters, which was a little counter-intuitive).

I’ve thought about how to create passwords which included at least one character from each set. My first ideas were around generating a password, then checking that it contained at least one character from each set and if not, replacing some of the characters with ones from the missing set. However this train of thought quickly ran into problems when I had to decide which character to replace. Choosing something fixed (like the first one, last one, etc) is too predictable. If I choose a random one, I run the risk of overwriting previous change. So finally I realized that there is a simple solution: just re-generate the password until it satisfies all of the constraints. Although this might seem like a brute-force solution, in practice its speed is indistinguishable from a constant-time solution.

Below you have the new and improved YARPG:

I’ve also updated the [original posting](http://hype-free.blogspot.com/2006/10/javascript-password-generator.html). You can get the source code for it by looking at the source of this webpage, or from my SVN repository: [js\_password\_generator.html](http://code.google.com/p/hype-free/source/browse/trunk/js_password_generator.html). Hopefully you find it useful! *Picture taken from [cjc4454’s photostream](http://www.flickr.com/photos/cjc4454/) with permission.*