paper-auth 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/.DS_Store +0 -0
- data/lib/paper-auth/.DS_Store +0 -0
- data/lib/paper-auth/version.rb +3 -0
- data/lib/paper-auth.rb +122 -0
- data/paper-auth.gemspec +27 -0
- data/templates/.DS_Store +0 -0
- data/templates/fonts/.DS_Store +0 -0
- data/templates/fonts/PTMono.ttf +0 -0
- data/templates/paper.css +23 -0
- data/templates/paper.html.erb +43 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed11e6dc83d42929f6038911106027593b61228f
|
4
|
+
data.tar.gz: 4ec439661e864c17736cf8ae622bf02a0d62c7be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f14252c03a5a7713190dbb02f95da44bfd7a96bb43b91792e16f2d2332fc4568e530f5c94b76756c522f5fc523b6197eaed7193488c5c9c28e37b1497800a957
|
7
|
+
data.tar.gz: 9ffb856493917ceb4636dc03d13980bc0a1a3bfd631c886153a2440434c33fd376719564b0ea93ac2fa4bdcbc2542ee5deea420f296673be3ecc157a8349f016
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Paper::Auth
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'paper-auth'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install paper-auth
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/paper-auth/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
data/lib/paper-auth.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require "paper-auth/version"
|
2
|
+
require "hashie"
|
3
|
+
require "digest"
|
4
|
+
require "pdfkit"
|
5
|
+
require "erb"
|
6
|
+
|
7
|
+
class PaperAuth
|
8
|
+
def initialize ()
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(id, key)
|
12
|
+
# Create two hashes, and remove 3 characters from the end
|
13
|
+
hash1 = Digest::SHA2.new(512).hexdigest("#{id}#{key}")[0..-4].upcase
|
14
|
+
hash2 = Digest::SHA2.new(512).hexdigest("#{key}#{id}")[0..-4].upcase
|
15
|
+
# Combine the two hashes to have 250 random characters
|
16
|
+
hash = "#{hash1}#{hash2}"
|
17
|
+
# Divide the 250 characters into a 10x5 array with 5 characters in each
|
18
|
+
table = hash.scan(/#{"(.{5})"*5}/)
|
19
|
+
# Initialize the two parts (top and bottom half)
|
20
|
+
pair1 = Array.new
|
21
|
+
pair2 = Array.new
|
22
|
+
# For each array grid...
|
23
|
+
for i in 0...10 do
|
24
|
+
for j in 0...5 do
|
25
|
+
# Strip generates either 0 or 1. If it is 0, 2 characters will be removed from the text. If it is 1, 3 characters will be removed from the text.
|
26
|
+
strip = rand(0..1)
|
27
|
+
# Generate two random numbers which will be the positition of the number that will be moved.
|
28
|
+
remove1 = rand(0..4)
|
29
|
+
remove2 = rand(0..4)
|
30
|
+
# Make sure that the numbers are not equal.
|
31
|
+
while remove1 == remove2
|
32
|
+
remove2 = rand(0..4)
|
33
|
+
end
|
34
|
+
# If strip is 0, remove 2 characters.
|
35
|
+
if strip == 0
|
36
|
+
# Find the current box we are edititing and split it into characters.
|
37
|
+
text = table[i][j].split(//)
|
38
|
+
# Replace two of the numbers with a blank.
|
39
|
+
text[remove1] = "_"
|
40
|
+
text[remove2] = "_"
|
41
|
+
# Initialize and update the value.
|
42
|
+
pair1[i] ||= []
|
43
|
+
pair1[i][j] = text.join
|
44
|
+
# Find the current box we are edititing and split it into characters.
|
45
|
+
text = table[i][j].split(//)
|
46
|
+
# Save the value of the characters we will be removing.
|
47
|
+
char1 = text[remove1]
|
48
|
+
char2 = text[remove2]
|
49
|
+
# Create a new temporary array which default contains "_".
|
50
|
+
text = Array.new(5, "_")
|
51
|
+
# Update the Array to only hold the two numbers.
|
52
|
+
text[remove1] = char1
|
53
|
+
text[remove2] = char2
|
54
|
+
# Initialize and update the value.
|
55
|
+
pair2[i] ||= []
|
56
|
+
pair2[i][j] = text.join
|
57
|
+
else
|
58
|
+
# Find the current box we are edititing and split it into characters.
|
59
|
+
text = table[i][j].split(//)
|
60
|
+
# Save the value of the characters we will be removing.
|
61
|
+
char1 = text[remove1]
|
62
|
+
char2 = text[remove2]
|
63
|
+
# Create a new temporary array which default contains "_".
|
64
|
+
text = Array.new(5, "_")
|
65
|
+
# Update the Array to only hold the two numbers.
|
66
|
+
text[remove1] = char1
|
67
|
+
text[remove2] = char2
|
68
|
+
# Initialize and update the value.
|
69
|
+
pair1[i] ||= []
|
70
|
+
pair1[i][j] = text.join
|
71
|
+
# Find the current box we are edititing and split it into characters.
|
72
|
+
text = table[i][j].split(//)
|
73
|
+
# Replace two of the numbers with a blank.
|
74
|
+
text[remove1] = "_"
|
75
|
+
text[remove2] = "_"
|
76
|
+
# Initialize and update the value.
|
77
|
+
pair2[i] ||= []
|
78
|
+
pair2[i][j] = text.join
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
# Load the template.
|
83
|
+
templates = File.expand_path('../templates', File.dirname(__FILE__))
|
84
|
+
content = File.read(templates + '/paper.html.erb')
|
85
|
+
template = ERB.new(content)
|
86
|
+
# Generate PDF from the template.
|
87
|
+
kit = PDFKit.new(template.result(binding))
|
88
|
+
kit.stylesheets << templates + '/paper.css'
|
89
|
+
return file = kit.to_file('result.pdf')
|
90
|
+
end
|
91
|
+
|
92
|
+
def get
|
93
|
+
# Generate random number and letter.
|
94
|
+
number = rand(1..10)
|
95
|
+
letter = rand(65..69)
|
96
|
+
letter = letter.chr
|
97
|
+
# Return random coordinate.
|
98
|
+
return "#{number}#{letter}"
|
99
|
+
end
|
100
|
+
|
101
|
+
def verify(id, key, grid, value)
|
102
|
+
# Create two hashes, and remove 3 characters from the end
|
103
|
+
hash1 = Digest::SHA2.new(512).hexdigest("#{id}#{key}")[0..-4].upcase
|
104
|
+
hash2 = Digest::SHA2.new(512).hexdigest("#{key}#{id}")[0..-4].upcase
|
105
|
+
# Combine the two hashes to have 250 random characters
|
106
|
+
hash = "#{hash1}#{hash2}"
|
107
|
+
# Divide the 250 characters into a 10x5 array with 5 characters in each
|
108
|
+
table = hash.scan(/#{"(.{5})"*5}/)
|
109
|
+
# Split the coordinate of the grid point.
|
110
|
+
grid = grid.split(//)
|
111
|
+
number = grid[0].to_i - 1
|
112
|
+
letter = grid[1].upcase.ord - 65
|
113
|
+
# Search the table for the correct answer.
|
114
|
+
answer = table[number][letter].downcase
|
115
|
+
# If the answer equals to the value, then it returns true, otherwise it returns false.
|
116
|
+
if answer == value.downcase
|
117
|
+
return true
|
118
|
+
else
|
119
|
+
return false
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
data/paper-auth.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'paper-auth/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "paper-auth"
|
8
|
+
spec.version = PaperAuth::VERSION
|
9
|
+
spec.authors = ["Manthan Mallikarjun"]
|
10
|
+
spec.email = ["manthan@nahtnam.com"]
|
11
|
+
spec.summary = %q{A paper based two factor authenticaiton.}
|
12
|
+
spec.description = %q{A paper based two factor authenticaiton.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
spec.add_dependency "hashie"
|
25
|
+
spec.add_dependency "pdfkit"
|
26
|
+
spec.add_dependency "wkhtmltopdf-binary"
|
27
|
+
end
|
data/templates/.DS_Store
ADDED
Binary file
|
Binary file
|
Binary file
|
data/templates/paper.css
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
body {
|
2
|
+
text-align: center;
|
3
|
+
font-family: "Courier New", Courier, monospace;
|
4
|
+
}
|
5
|
+
|
6
|
+
table {
|
7
|
+
width: 100%;
|
8
|
+
height: 50%;
|
9
|
+
border: none;
|
10
|
+
text-align: center;
|
11
|
+
}
|
12
|
+
|
13
|
+
#pair2 {
|
14
|
+
-webkit-transform: rotate(180deg) scaleX(-1);
|
15
|
+
-moz-transform: rotate(180deg) scaleX(-1);
|
16
|
+
-o-transform: rotate(180deg) scaleX(-1);
|
17
|
+
-ms-transform: rotate(180deg) scaleX(-1);
|
18
|
+
transform: rotate(180deg) scaleX(-1);
|
19
|
+
}
|
20
|
+
|
21
|
+
hr {
|
22
|
+
border: 1px dashed;
|
23
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<h1>Paper Authentication</h1>
|
2
|
+
<table id="pair1">
|
3
|
+
<tr>
|
4
|
+
<td></td>
|
5
|
+
<td><strong>A</strong></td>
|
6
|
+
<td><strong>B</strong></td>
|
7
|
+
<td><strong>C</strong></td>
|
8
|
+
<td><strong>D</strong></td>
|
9
|
+
<td><strong>E</strong></td>
|
10
|
+
<td></td>
|
11
|
+
</tr>
|
12
|
+
<% for i in 0...10 %>
|
13
|
+
<tr>
|
14
|
+
<td><strong><%= i+1 %></strong></td>
|
15
|
+
<% for j in 0...5 %>
|
16
|
+
<td><%= pair1[i][j] %></td>
|
17
|
+
<% end %>
|
18
|
+
<td><strong><%= i+1 %></strong></td>
|
19
|
+
</tr>
|
20
|
+
<% end %>
|
21
|
+
</table>
|
22
|
+
<br>
|
23
|
+
<hr>
|
24
|
+
</br>
|
25
|
+
<table id="pair2">
|
26
|
+
<tr>
|
27
|
+
<td></td>
|
28
|
+
<td><strong>A</strong></td>
|
29
|
+
<td><strong>B</strong></td>
|
30
|
+
<td><strong>C</strong></td>
|
31
|
+
<td><strong>D</strong></td>
|
32
|
+
<td><strong>E</strong></td>
|
33
|
+
</tr>
|
34
|
+
<% for i in 0...10 %>
|
35
|
+
<tr>
|
36
|
+
<td><strong><%= i+1 %></strong></td>
|
37
|
+
<% for j in 0...5 %>
|
38
|
+
<td><%= pair2[i][j] %></td>
|
39
|
+
<% end %>
|
40
|
+
<td><strong><%= i+1 %></strong></td>
|
41
|
+
</tr>
|
42
|
+
<% end %>
|
43
|
+
</table>
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paper-auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Manthan Mallikarjun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: hashie
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pdfkit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: wkhtmltopdf-binary
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: A paper based two factor authenticaiton.
|
84
|
+
email:
|
85
|
+
- manthan@nahtnam.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".DS_Store"
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/.DS_Store
|
97
|
+
- lib/paper-auth.rb
|
98
|
+
- lib/paper-auth/.DS_Store
|
99
|
+
- lib/paper-auth/version.rb
|
100
|
+
- paper-auth.gemspec
|
101
|
+
- templates/.DS_Store
|
102
|
+
- templates/fonts/.DS_Store
|
103
|
+
- templates/fonts/PTMono.ttf
|
104
|
+
- templates/paper.css
|
105
|
+
- templates/paper.html.erb
|
106
|
+
homepage: ''
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.4.5
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: A paper based two factor authenticaiton.
|
130
|
+
test_files: []
|