SixArm.com » Ruby » PasswordAttribute module to add strong passwords to ActiveRecord

Author

Joel Parker Henderson, [email protected]

Copyright

Copyright © 2006-2011 Joel Parker Henderson

License

See LICENSE.txt file

Easy way to add BCrypt strong password capability to an ActiveRecord model.

This is typically useful to add to a Ruby On Rails ActiveRecord user model.

Example:

require 'sixarm_ruby_password_attribute'
class User
  include PasswordAttribute
end

Example: create new user

user=User.new
user.password='secret'  # automatically converts plain text to bcrypt
user.save

Example: is a user’s password valid?

if user.password=='secret' 
  # password is valid
else
  # password is invalid
end

u.password='secret'
=> user's password is now secret

u.password=='secret'
=> true

u.password=='xxx'
=> false