Skip to content

A Ruby on Rails plugin to automate hashing an activerecord field using bcrypt; an activerecord wrapper for bcrypt-ruby

License

Notifications You must be signed in to change notification settings

kswope/auto_hash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

# In Model
class User < ActiveRecord::Base
  auto_hash :password
end

# Elsewhere
user = User.create(:email => "[email protected]", :password => "asdf")
user.password #=> "$2a$10$0DvrQ.HMKRySMJrn0cGEM.AcesF82tkeBfNLTZTZ.VSWePihZD3mG"
user.password == "asdf" # => true

# works with updating fields also
user = User.find_by_email("[email protected]")
user.password = "better_password"
user.password == "better_password" # => true

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 © 2010 Kevin Swope. See LICENSE for details.

About

A Ruby on Rails plugin to automate hashing an activerecord field using bcrypt; an activerecord wrapper for bcrypt-ruby

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages