Straight from the Rails API
# Schema: User(name:string, password_digest:string) class User < ActiveRecord::Base has_secure_password end user = User.new(:name => "david", :password => "", :password_confirmation => "nomatch") user.save # => false, password required user.password = "mUc3m00RsqyRe" user.save # => false, confirmation doesn't match user.password_confirmation = "mUc3m00RsqyRe" user.save # => true user.authenticate("notright") # => false user.authenticate("mUc3m00RsqyRe") # => user
You need to include :password_confirmation => "pass in your hash!
That's correct, therefore, looking at has_secure_password , you want to execute BCrypt::Password.create(unencrypted_password) to get it. To accomplish the above, you will need a bcrypt-ruby stone.
source share