revent 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/revent/captcha.rb +8 -7
- metadata +2 -2
data/lib/revent/captcha.rb
CHANGED
@@ -9,10 +9,11 @@ module Revent
|
|
9
9
|
JIGGLE = 15
|
10
10
|
WOBBLE = 20
|
11
11
|
|
12
|
-
|
12
|
+
# valid_period: [sec]
|
13
|
+
def initialize(key, length, valid_period)
|
13
14
|
@b = Crypt::Blowfish.new(key)
|
14
|
-
@
|
15
|
-
@
|
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, @
|
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 < @
|
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(@
|
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*@
|
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.
|
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-
|
12
|
+
date: 2008-02-29 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|