dev-random-passwords 0.0.4 → 0.0.6
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.
- checksums.yaml +4 -4
- data/bin/randompasswords +8 -2
- data/lib/dev-random-passwords.rb +45 -10
- data/lib/dev-random-passwords/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8261b4136ad87c2f35d7a26800ada66e5f536a60
|
4
|
+
data.tar.gz: d9d61fc0286e9a623d7381ff363e1eaf935206d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a52f5af0bf2212ffd1ed6838f4f68e1d6b114ea60e3cb8683a958ba7ac1424f7929d0691accba4b72df6ff4eb950542fe4bb75af74e68a614bd8f61fb65cff4
|
7
|
+
data.tar.gz: b57885e98f43a38c132677560a02f4358af2cd5998f867e79b57b006e0b77a108f2ed97d717916602d68a3904998031c2835f4302f15b7acca469800f7c6a19b
|
data/bin/randompasswords
CHANGED
@@ -12,7 +12,8 @@ options = {
|
|
12
12
|
'include' => nil,
|
13
13
|
'exclude' => nil,
|
14
14
|
'length' => 8,
|
15
|
-
'requirements' => nil
|
15
|
+
'requirements' => nil,
|
16
|
+
'hardware' => false
|
16
17
|
}
|
17
18
|
|
18
19
|
|
@@ -21,7 +22,7 @@ opts = OptionParser.new do |opts|
|
|
21
22
|
opts.separator ""
|
22
23
|
opts.separator "Specific options:"
|
23
24
|
|
24
|
-
opts.on("-l", "--length [DIGITS]", "Password length in digits") do |length|
|
25
|
+
opts.on("-l", "--length [DIGITS]", "Password length in digits (default is 8)") do |length|
|
25
26
|
options['length'] = length.to_i
|
26
27
|
end
|
27
28
|
|
@@ -57,10 +58,15 @@ opts = OptionParser.new do |opts|
|
|
57
58
|
options['requirements'] = req_hash
|
58
59
|
end
|
59
60
|
|
61
|
+
opts.on("-H", "--hardware", "Use hardware random generators defaults back if none found") do |hw|
|
62
|
+
options['hardware'] = true
|
63
|
+
end
|
60
64
|
|
61
65
|
#Help
|
62
66
|
opts.on_tail("-h", "--help", "Show this message") do
|
67
|
+
print "\n"
|
63
68
|
puts opts
|
69
|
+
print "\n"
|
64
70
|
exit
|
65
71
|
end
|
66
72
|
|
data/lib/dev-random-passwords.rb
CHANGED
@@ -13,29 +13,64 @@ module DevRandomPasswords
|
|
13
13
|
@charset = LOWERCASE_CHARS + UPPERCASE_CHARS + DIGITS + SPECIAL_CHARS
|
14
14
|
@char_length = 8
|
15
15
|
@requirements = nil
|
16
|
+
@hardware_random = false
|
16
17
|
end
|
17
18
|
|
18
19
|
def get_byte
|
19
|
-
if
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
if @hardware_random == true
|
21
|
+
|
22
|
+
if File.exist?('/dev/hwrng')
|
23
|
+
if File.readable?('/dev/hwrng')
|
24
|
+
random_file = File.new('/dev/hwrng', 'r')
|
25
|
+
random_byte = random_file.read(1).ord
|
26
|
+
random_file.close
|
27
|
+
if random_byte
|
28
|
+
return random_byte
|
29
|
+
end
|
30
|
+
else
|
31
|
+
raise "/dev/hwrng is not readable by the current user please change permissions on this file"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if File.exist?('/dev/hwrandom')
|
36
|
+
if File.readable?('/dev/hwrandom')
|
37
|
+
random_file = File.new('/dev/hwrandom', 'r')
|
38
|
+
random_byte = random_file.read(1).ord
|
39
|
+
random_file.close
|
40
|
+
if random_byte
|
41
|
+
return random_byte
|
42
|
+
end
|
43
|
+
else
|
44
|
+
raise "/dev/hwrandom is not readable by the current user please change permissions on this file"
|
45
|
+
end
|
27
46
|
end
|
28
47
|
|
29
|
-
|
48
|
+
end
|
49
|
+
|
50
|
+
if File.exist?('/dev/random')
|
30
51
|
if File.readable?('/dev/random')
|
31
52
|
random_file = File.new('/dev/random', 'r')
|
32
53
|
random_byte = random_file.read(1).ord
|
33
54
|
random_file.close
|
34
|
-
|
55
|
+
if random_byte
|
56
|
+
return random_byte
|
57
|
+
end
|
35
58
|
else
|
36
59
|
raise "/dev/random is not readable by the current user please change permissions on this file"
|
37
60
|
end
|
38
61
|
|
62
|
+
elsif File.exist?('/dev/urandom')
|
63
|
+
if File.readable?('/dev/urandom')
|
64
|
+
random_file = File.new('/dev/urandom', 'r')
|
65
|
+
random_byte = random_file.read(1).ord
|
66
|
+
random_file.close
|
67
|
+
if random_byte
|
68
|
+
return random_byte
|
69
|
+
end
|
70
|
+
else
|
71
|
+
raise "/dev/urandom is not readable by the current user please change permissions on this file"
|
72
|
+
end
|
73
|
+
|
39
74
|
else
|
40
75
|
raise "Could not find a random number generator on your system"
|
41
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev-random-passwords
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|