Generate random password in Rails

I am using Restful_authentication plugin for one of my projects.
As part of my user creation workflow, system should to generate a random
password for the new user.
So, look at my password creation behaviour:

* generate uncrypted password
* send this with e-mail notification
* crypt the password
class CandidatesController < ApplicationController ... if @candidate.valid? Notifier.deliver_inv(, candidate.crypted_password) candidate.encrypt_password end end require 'digest/sha1' class User < ActiveRecord::Base ... def encrypt_password self.salt = Digest::SHA1.hexdigest("--#{}--#{name}--") self.crypted_password = encrypt(self.crypted_password) save(false) end protected def save_password (self.crypted_password = password) unless self.crypted_password end ... end

class Candidate < User


before_save :save_password
before_validation_on_create do |u|
u.password = { (rand(122-97) + 97).chr }.join
u.password_confirmation = u.password