Rails3 Custom Password Validators

As I was writing validators for the User class of a Rails 3 app, I wanted to make sure that people wouldn't use their names, usernames, or email addresses as passwords.
Unfortunately I couldn't find a way to accomplish this with the built-in validators. Fortunately Rails 3 makes it easy to write your own custom validators.

Here's an extract of my User class

The "password => true" tells Rails to call my custom validator which, in this case, has to be called password_format.rb.

I keep my custom validators in /lib/validators, so I need to add the following to my config/application.rb file:

And finally the validator itself:

(Don't forget to write the specs to test this! :-)