Wednesday, March 19, 2008

Password Validation

From: here
  • Users must supply a passphrase when signing up
  • Passphrases should be between 8 and 64 characters in length
  • It is not necessary to supply a passphrase when updating an existing record
  • Confirmation must be supplied when setting a new passphrase on an existing record

These requirements lead to the following validations:


  MINIMUM_PASSPHRASE_LENGTH     = 8
MAXIMUM_PASSPHRASE_LENGTH = 64

validates_presence_of  :passphrase,
 :on => :create
validates_length_of  :passphrase,
 :in => MINIMUM_PASSPHRASE_LENGTH..MAXIMUM_PASSPHRASE_LENGTH,
 :if => Proc.new { |u| !u.passphrase.blank? }
validates_confirmation_of  :passphrase,
 :if => Proc.new { |u| !u.passphrase.blank? }

No comments: