passlock 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/passlock.rb +93 -92
- data/lib/passlock/class.rb +29 -27
- data/lib/passlock/version.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26eb8e67214b0f31c36a251687d4f9d4bed5a0b2
|
4
|
+
data.tar.gz: 8128e88426c9f8e7c38a66deba3d5b398cd00a79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d72a5389a118d9e7191e1f7e8d814c5ca526059775fda22b6b373e81e85eaca41cd63435699d4ba7bbd61d5d79ee3b399b93fae308ed0401769100c3185922b
|
7
|
+
data.tar.gz: 7474d629676e56bb4eb2f16f9a56d772c06346341c4cef44b8c7988325a68ceba3b5cd8ba3e0700627e3b9b0b548e57e0b78d09e87488ce0f3acd977f46d5462
|
data/lib/passlock.rb
CHANGED
@@ -6,113 +6,114 @@ require 'digest/sha2'
|
|
6
6
|
require 'hmac-sha1'
|
7
7
|
require 'securerandom'
|
8
8
|
|
9
|
+
# PassLock base module
|
9
10
|
module PassLock
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
@opts = {
|
12
|
+
'number' => '1234567890',
|
13
|
+
'upletter' => 'qwertyuiopasdfghjklzxcvbnm'.upcase,
|
14
|
+
'downletter' => 'qwertyuiopasdfghjklzxcvbnm',
|
15
|
+
'symbols' => %q{`~!@#$%^&*()_+-=[]{}\|;':",.<>/?}
|
16
|
+
}
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
length.to_i.times do
|
32
|
-
result += chars.sample
|
33
|
-
end
|
34
|
-
result
|
18
|
+
# A randomly generated passord.
|
19
|
+
# @param options [Array] Options for the password given in strings. Available strings `number` `upletter` `downletter` `symbol`
|
20
|
+
# @param length [Integer] How long the password will be
|
21
|
+
# @return [String] Returns the Base64-encoded version of the password.
|
22
|
+
def self.cpass(options, length)
|
23
|
+
options = options != Array || options.empty? ? options : %w{number upletter downletter symbol}
|
24
|
+
length = length.is_a(Integer) && length > 0 ? length : 10
|
25
|
+
chars = []
|
26
|
+
result = ""
|
27
|
+
options.each do |flag|
|
28
|
+
if not @opts[flag].nil?
|
29
|
+
chars.concat(@opts[flag].scan(/./))
|
30
|
+
end
|
35
31
|
end
|
36
|
-
|
37
|
-
|
38
|
-
# @return [String] The UUID
|
39
|
-
def self.uuid
|
40
|
-
SecureRandom.uuid
|
32
|
+
length.to_i.times do
|
33
|
+
result += chars.sample
|
41
34
|
end
|
35
|
+
result
|
36
|
+
end
|
42
37
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
layers.times do
|
49
|
-
pass = Base64.encode64 pass
|
50
|
-
end
|
51
|
-
pass
|
52
|
-
end
|
38
|
+
# Creates a UUID.
|
39
|
+
# @return [String] The UUID
|
40
|
+
def self.uuid
|
41
|
+
SecureRandom.uuid
|
42
|
+
end
|
53
43
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
pass
|
44
|
+
# Encodes password in Base64.
|
45
|
+
# @param pass [String] The password to be encoded
|
46
|
+
# @param layers [Fixnum] The amount of layering
|
47
|
+
# @return [String] Returns the Base64-encoded version of the password
|
48
|
+
def self.base64(pass, layers: 1)
|
49
|
+
layers.times do
|
50
|
+
pass = Base64.encode64 pass
|
63
51
|
end
|
52
|
+
pass
|
53
|
+
end
|
64
54
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
pass
|
55
|
+
# Creats a SHA1 hash.
|
56
|
+
# @param pass [String] The password to be encoded
|
57
|
+
# @param layers [Fixnum] The amount of layering
|
58
|
+
# @return [String] The SHA1 hash
|
59
|
+
def self.sha1(pass, layers: 1)
|
60
|
+
layers.times do
|
61
|
+
pass = Digest::SHA1.hexdigest pass
|
74
62
|
end
|
63
|
+
pass
|
64
|
+
end
|
75
65
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
-
pass
|
66
|
+
# Creats a SHA256 hash.
|
67
|
+
# @param pass [String] The password to be encoded
|
68
|
+
# @param layers [Fixnum] The amount of layering
|
69
|
+
# @return [String] The SHA256 hash
|
70
|
+
def self.sha256(pass, layers: 1)
|
71
|
+
layers.times do
|
72
|
+
pass = Digest::SHA256.new().update(pass).to_s
|
85
73
|
end
|
74
|
+
pass
|
75
|
+
end
|
76
|
+
|
77
|
+
# Creats a SHA384 hash.
|
78
|
+
# @param pass [String] The password to be encoded
|
79
|
+
# @param layers [Fixnum] The amount of layering
|
80
|
+
# @return [String] The SHA384 hash
|
81
|
+
def self.sha384(pass, layers: 1)
|
82
|
+
layers.times do
|
83
|
+
pass = Digest::SHA384.new.update(pass).to_s
|
84
|
+
end
|
85
|
+
pass
|
86
|
+
end
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
95
|
-
pass
|
88
|
+
# Creats a SHA512 hash.
|
89
|
+
# @param pass [String] The password to be encoded
|
90
|
+
# @param layers [Fixnum] The amount of layering
|
91
|
+
# @return [String] The SHA512 hash
|
92
|
+
def self.sha512(pass, layers: 1)
|
93
|
+
layers.times do
|
94
|
+
pass = Digest::SHA512.new.update(pass).to_s
|
96
95
|
end
|
96
|
+
pass
|
97
|
+
end
|
97
98
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
end
|
106
|
-
pass
|
99
|
+
# Encodes password in Base64 encoded hash.
|
100
|
+
# @param pass [String] The password to be encoded
|
101
|
+
# @param layers [Fixnum] The amount of layering
|
102
|
+
# @return [String] The Base64-encoded hash
|
103
|
+
def self.base64hash(pass, layers: 1)
|
104
|
+
layers.times do
|
105
|
+
pass = Base64.encode64((HMAC::SHA1.new(pass) << 'base').digest).strip
|
107
106
|
end
|
107
|
+
pass
|
108
|
+
end
|
108
109
|
|
109
|
-
|
110
|
+
class Decode
|
110
111
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
112
|
+
# Decodes password in Base64.
|
113
|
+
# @param base [String] The Base64-encoded of the original password
|
114
|
+
# @return [String] Returns the decoded password
|
115
|
+
def self.base64(base)
|
116
|
+
Base64.decode64 base
|
117
117
|
end
|
118
|
-
end
|
118
|
+
end
|
119
|
+
end
|
data/lib/passlock/class.rb
CHANGED
@@ -2,36 +2,38 @@ require 'base64'
|
|
2
2
|
require 'digest/sha1'
|
3
3
|
require 'digest/sha2'
|
4
4
|
require 'hmac-sha1'
|
5
|
+
|
6
|
+
# String module
|
5
7
|
class String
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
# @see PassLock#base64
|
9
|
+
def to_base
|
10
|
+
Base64.encode64 self
|
11
|
+
end
|
12
|
+
alias_method :to_base64, to_base
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
# @see PassLock#sha1
|
15
|
+
def to_sha1
|
16
|
+
Digest::SHA1.hexdigest self
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
# @see PassLock#sha256
|
20
|
+
def to_sha256
|
21
|
+
Digest::SHA256.new.update(self).to_s
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
# @see PassLock#sha384
|
25
|
+
def to_sha384
|
26
|
+
Digest::SHA384.new.update(self).to_s
|
27
|
+
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
# @see PassLock#sha512
|
30
|
+
def to_sha512
|
31
|
+
Digest::SHA512.new.update(self).to_s
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
34
|
+
# @see PassLock#base64hash
|
35
|
+
def to_basehash
|
36
|
+
Base64.encode64((HMAC::SHA1.new(self) << 'base').digest).strip
|
37
|
+
end
|
38
|
+
alias_method :to_base64hash, to_basehash
|
39
|
+
end
|
data/lib/passlock/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
module PassLock
|
2
|
-
|
3
|
-
|
4
|
-
end
|
2
|
+
# The version of the gem installed.
|
3
|
+
VERSION = '0.0.6'.freeze
|
4
|
+
end
|