-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using BCrypt #177
Comments
Have you tried using ActiveModel's has_secure_password method? Something like this should work (untested): class User < CouchRest::Model::Base
use_database "sample"
timestamps!
has_secure_password
property :email, String
property :password_digest, String
design do
view :by_email
end
end You use it the same way as in the user = User.new(email: '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
User.find_by_email('david').try(:authenticate, 'notright') # => false
User.find_by_email('david').try(:authenticate, 'mUc3m00RsqyRe') # => user |
Thanks @jhecking, I think that's what I'm looking for however it seems to be telling me |
Sorry, looks like you need to |
Awesome, thanks! |
I just noticed that by creating some new users, they don't appear in the actual DB (I'm viewing it in Futon). I have the following code: require 'couchrest_model'
class User < CouchRest::Model::Base
include ActiveModel::SecurePassword
use_database 'sample'
has_secure_password
property :username, String
property :email, String
property :password_digest, String
timestamps!
design { view :by_email }
end
User.create(:username => 'rafalchmiel', :email => 'hi@rafalchmiel.com', :password => 'password')
User.create(:username => 'bar', :email => 'hi@bar.com', :password => 'password213')
User.create(:username => 'foo', :email => 'hi@foo.com', :password => 'password12111') After running it, no documents are inserted. However if I run all this except leave out |
has_secure_password adds a validation to your model that requires that you pass a password_confirmation property whenever you set or change the password. Jan
|
Super, thanks a lot! |
I'm not sure how to approach password storing in CouchDB. I'd like to use BCrypt and therefore do something like this:
However that tells me that
User::BCryptHash
is an uninitialized constant. Any way to make this work or am I just doing it wrong?The text was updated successfully, but these errors were encountered: