Class: Revent::CaptchaFactory
- Includes:
- Magick
- Defined in:
- lib/revent/captcha.rb
Constant Summary collapse
- JIGGLE =
15
- WOBBLE =
20
Instance Method Summary collapse
-
#correct?(code, encrypted_code_with_timestamp) ⇒ Boolean
Returns true if the code matches and within the valid period.
-
#initialize(key, length, valid_period) ⇒ CaptchaFactory
constructor
valid_period: [sec].
-
#new ⇒ Object
Returns [encrypted_code_with_timestamp, img].
Constructor Details
#initialize(key, length, valid_period) ⇒ CaptchaFactory
valid_period: [sec]
22 23 24 25 26 |
# File 'lib/revent/captcha.rb', line 22 def initialize(key, length, valid_period) @b = Crypt::Blowfish.new(key) @length = length @valid_period = valid_period end |
Instance Method Details
#correct?(code, encrypted_code_with_timestamp) ⇒ Boolean
Returns true if the code matches and within the valid period.
37 38 39 40 41 42 |
# File 'lib/revent/captcha.rb', line 37 def correct?(code, ) = @b.decrypt_string() code0 = .slice!(0, @length) = .to_i code.upcase == code0 and Time.now.to_i - < @valid_period end |