Skip to content
This repository
Newer
Older
100644 33 lines (27 sloc) 0.718 kb
be37c354 »
2011-10-23 BCrypt for passwords
1 module Clearance
2 module PasswordStrategies
3 module BCrypt
4 require 'bcrypt'
5
6 extend ActiveSupport::Concern
7
8 # Am I authenticated with given password?
9 #
10 # @param [String] plain-text password
11 # @return [true, false]
12 # @example
13 # user.authenticated?('password')
14 def authenticated?(password)
15 ::BCrypt::Password.new(encrypted_password) == password
16 end
17
18 def password=(new_password)
19 @password = new_password
20 if new_password.present?
21 self.encrypted_password = encrypt(new_password)
22 end
23 end
24
25 private
26
27 def encrypt(password)
28 ::BCrypt::Password.create(password)
29 end
30 end
31 end
32 end
Something went wrong with that request. Please try again.