auto_hash¶ ↑
A Ruby on Rails plugin to automate the cryptographic hashing of an activerecord field.
UPDATE: auto_hash has quickly evolved to be a activerecord plugin that merely wraps the excellent bcrypt-ruby library. bcrypt-ruby.rubyforge.org
Works with both rails 2x and 3x
WARNING: untested with ruby 1.9.2 at the moment. (Couldn’t get rails 3x to work with ruby 1.9.2 - too early I guess)
Synopsis¶ ↑
# In Model class User < ActiveRecord::Base auto_hash :password end # Elsewhere user = User.create(:email => "kevin@example.com", :password => "asdf") user.password #=> "$2a$10$0DvrQ.HMKRySMJrn0cGEM.AcesF82tkeBfNLTZTZ.VSWePihZD3mG" user.password == "asdf" # => true # works with updating fields also user = User.find_by_email("kevin@example.com") user.password = "better_password" user.password == "better_password" # => true
Rails configuration (nothing unusual)¶ ↑
For rails 2x, in environment.rb
Rails::Initializer.run do |config| do config.gem "auto_hash" end
For rails 3x, in Gemfile
gem "auto_hash"
Copyright¶ ↑
Copyright © 2010 Kevin Swope. See LICENSE for details.