New Rails Plugin: Sexy Temp Passwords

Posted on December 19, 2007

If you ever had to give a user a random password (reset, etc), it probably looked like:

sdf35’kfl235jfl

With the Sexy Temp Passwords plugin, now it’s trivial to give users a password like:

rebecca1539, alphabet2067, lazarus1412, etc

It combines a dictionary of common english names/words with 4 random digits between 1 and 9. (probability space of ~6,769,323 unique passwords)

Installation

ruby script/plugin install \
http://sexy-temp-passwords.googlecode.com/svn/sexy_temp_passwords/

Example Usage

class User < ActiveRecord::Base
  include SexyTempPasswords

  def reset_password
    # Not that you'd ever store the plaintext password, but for demonstration purposes:
    self.password = User.sexy_temp_password
    save!
  end

end

u = User.find(:first)
u.reset_password
u.reload.password # 'allison1437' or whatever random password was generated

See more at Agile Web Development and the plugin page at google code.