revent 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/revent/captcha.rb +8 -7
  2. metadata +2 -2
@@ -9,10 +9,11 @@ module Revent
9
9
  JIGGLE = 15
10
10
  WOBBLE = 20
11
11
 
12
- def initialize(key, code_length, valid_period_in_sec)
12
+ # valid_period: [sec]
13
+ def initialize(key, length, valid_period)
13
14
  @b = Crypt::Blowfish.new(key)
14
- @code_length = code_length
15
- @valid_period_in_sec = valid_period_in_sec
15
+ @length = length
16
+ @valid_period = valid_period
16
17
  end
17
18
 
18
19
  # Returns [encrypted_code_with_timestamp, img].
@@ -26,9 +27,9 @@ module Revent
26
27
  # Returns true if the code matches and within the valid period.
27
28
  def correct?(code, encrypted_code_with_timestamp)
28
29
  code_with_timestamp = @b.decrypt_string(encrypted_code_with_timestamp)
29
- code0 = code_with_timestamp.slice!(0, @code_length)
30
+ code0 = code_with_timestamp.slice!(0, @length)
30
31
  timestamp0 = code_with_timestamp.to_i
31
- code.upcase == code0 and Time.now.to_i - timestamp0 < @valid_period_in_sec
32
+ code.upcase == code0 and Time.now.to_i - timestamp0 < @valid_period
32
33
  end
33
34
 
34
35
  private
@@ -38,10 +39,10 @@ module Revent
38
39
  def private_new
39
40
  code_array = []
40
41
  voca_length = VOCA.length
41
- 1.upto(@code_length) { code_array << VOCA[rand(voca_length)] }
42
+ 1.upto(@length) { code_array << VOCA[rand(voca_length)] }
42
43
  granite = Magick::ImageList.new('granite:')
43
44
  canvas = Magick::ImageList.new
44
- canvas.new_image(33*@code_length, 40, Magick::TextureFill.new(granite))
45
+ canvas.new_image(33*@length, 40, Magick::TextureFill.new(granite))
45
46
  text = Magick::Draw.new
46
47
  #text.font_family = 'times'
47
48
  text.pointsize = 40
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: revent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngoc DAO Thanh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-26 00:00:00 +09:00
12
+ date: 2008-02-29 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15