has secure password memo

stephen murdoch
2011-10-24T00:35:33Z

hspm.rb

| # some notes on using has_secure_password
|
| class User < ActiveRecord::Base
| has_secure_password
|
| attr_accessible :login_name, :password, :password_confirmation
|
| # secure_password.rb already checks for presence of :password_digest
| # so we can assume that a password is present if that validation passes
| # and thus, we don't need to explicitly check for presence of password
| validates :password,
| :length => { :minimum => 6 }, :if => :password_digest_changed?
|
| # secure_password.rb also checks for confirmation of :password
| # but we also have to check for presence of :password_confirmation
| validates :password_confirmation,
| :presence=>true, :if => :password_digest_changed?
|
| ___
| # In `config/locales/en.yml` make sure that errors on
| # the password_digest field refer to "Password" as it's more human friendly
|
| en:
| hello: "Hello world"
|
| activerecord:
| attributes:
| user:
| password_digest: "Password"