password_list_generator 0.1
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 +7 -0
- data/bin/pwgen +107 -0
- data/lib/password_list_generator/generator.rb +48 -0
- data/lib/password_list_generator/password.rb +40 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af7c818191d93f55e126cd9ae899e1b73ff6bd7d
|
4
|
+
data.tar.gz: 8c4d0d2c5eada6099f0c18b5a2b0c94d2bfbf86f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3347e6ea74db08b3714c916e901626fd4f31856623b5cc5484228379eb8f5bbab11daeb87e69dee8494fc35793749b2677cdd91d44e0271ed38a3eb0a0cec45
|
7
|
+
data.tar.gz: e9c10812f9e29024af45bb5507e7e91ca179747b2546fa158612391e754184cb43b78db897181bfc461a3faab74e9df5e01100288227388bc1a9da67207e7285
|
data/bin/pwgen
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'etc'
|
4
|
+
require 'password_list_generator'
|
5
|
+
require 'optparse'
|
6
|
+
require 'ostruct'
|
7
|
+
|
8
|
+
# To use without rubygem: ruby -Ilib ./bin/genpw
|
9
|
+
|
10
|
+
user = Etc.getlogin
|
11
|
+
default_output = Dir.home(user) + "/password.txt"
|
12
|
+
|
13
|
+
options = OpenStruct.new
|
14
|
+
options.output_file = default_output
|
15
|
+
options.count = 100
|
16
|
+
options.uppercase = true
|
17
|
+
options.numeric = true
|
18
|
+
options.symbol = true
|
19
|
+
options.min = 14
|
20
|
+
options.max = 32
|
21
|
+
|
22
|
+
opts = OptionParser.new do |opts|
|
23
|
+
opts.banner = "Usage: genpw [options]"
|
24
|
+
opts.separator ""
|
25
|
+
opts.separator "Examples:"
|
26
|
+
opts.separator " pwgen --o /tmp/password.txt"
|
27
|
+
opts.separator " pwgen --uppercase false"
|
28
|
+
opts.separator "Options:"
|
29
|
+
|
30
|
+
opts.on("-o", "--output-file [#{default_output}]", "Ouput password file") do |output|
|
31
|
+
options.output_file = output
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on("-c", "--count [#{options.count}]", "Number of passwords to create") do |count|
|
35
|
+
options.count = count.to_i
|
36
|
+
|
37
|
+
if options.count == 0
|
38
|
+
puts "Count must be greater than 0"
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on("--min [#{options.min}]", "Minimum length of password") do |min|
|
44
|
+
options.min = min.to_i
|
45
|
+
|
46
|
+
if min_gte_max?(options.min, options.max)
|
47
|
+
puts "Minimum number of characters (#{options.min}) must be less than maximum (#{options.max})"
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on("--max [#{options.max}]", "Maximum length of password") do |max|
|
53
|
+
options.max = max.to_i
|
54
|
+
|
55
|
+
if min_gte_max?(options.min, options.max)
|
56
|
+
puts "Minimum number of characters (#{options.min}) must be less than maximum (#{options.max})"
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
opts.on("-u", "--uppercase [#{options.uppercase}]", "Include uppercase characters in password") do |upper|
|
62
|
+
options.uppercase = true_values.include? upper
|
63
|
+
end
|
64
|
+
|
65
|
+
opts.on("-n", "--numeric [#{options.numeric}]", "Include numerical characters in password") do |numeric|
|
66
|
+
options.numeric = true_values.include? numeric
|
67
|
+
end
|
68
|
+
|
69
|
+
opts.on("-s", "--symbol [#{options.symbol}]", "Include symbol (!@#$%) characters in password") do |symbol|
|
70
|
+
options.symbol = true_values.include? symbol
|
71
|
+
end
|
72
|
+
|
73
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
74
|
+
puts opts
|
75
|
+
exit
|
76
|
+
end
|
77
|
+
|
78
|
+
opts.on_tail("--version", "Show version") do
|
79
|
+
puts "Not yet implemented"
|
80
|
+
exit
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def min_gte_max?(min, max)
|
85
|
+
min >= max
|
86
|
+
end
|
87
|
+
|
88
|
+
def true_values
|
89
|
+
["1", "true", "t", "yes", "y"]
|
90
|
+
end
|
91
|
+
|
92
|
+
opts.parse!
|
93
|
+
|
94
|
+
passwords = PasswordListGenerator::Generator.new(options).generate
|
95
|
+
file = options.output_file
|
96
|
+
|
97
|
+
system "echo ' ' > #{file} \n\n"
|
98
|
+
system "echo 'Generated passwords meet the following requirements: ' >> #{file}"
|
99
|
+
system "echo 'Must have at least one lower case alphabetic character (a - z)' >> #{file}"
|
100
|
+
system "echo 'Must have at least one special character (!@#\$\%^&*())' >> #{file}" if options.symbol
|
101
|
+
system "echo 'Must have at least one numeric character (0 -9)' >> #{file}" if options.numeric
|
102
|
+
system "echo 'Must have at least one upper case alphabetic character (A - Z)' >> #{file}" if options.uppercase
|
103
|
+
system "echo 'Must have at least #{options.min} characters' >> #{file}"
|
104
|
+
system "echo 'Must have no more than #{options.max} characters' >> #{file}"
|
105
|
+
system "echo ' ' >> #{file}"
|
106
|
+
system "echo '" + passwords.map(&:to_s).join("\n\n") + "' >> #{file}"
|
107
|
+
puts "#{options.count} random passwords were generated into #{file}"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module PasswordListGenerator
|
4
|
+
class Generator
|
5
|
+
attr_accessor :characters_set, :config
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
build_characters_set
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate
|
13
|
+
passwords = []
|
14
|
+
|
15
|
+
1.upto(config.count) do
|
16
|
+
valid = false
|
17
|
+
random = ''
|
18
|
+
|
19
|
+
until valid
|
20
|
+
random_size = (config.min..config.max).to_a.shuffle.first
|
21
|
+
random = (1..random_size).map {|a| characters_set[SecureRandom.random_number(characters_set.size)]}.join
|
22
|
+
password = Password.new(random, config)
|
23
|
+
|
24
|
+
if password.valid?
|
25
|
+
passwords << password
|
26
|
+
valid = true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
passwords
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def build_characters_set
|
37
|
+
@characters_set = ('a'..'z').to_a
|
38
|
+
@characters_set += ('A'..'Z').to_a if config.uppercase
|
39
|
+
@characters_set += ('0'..'9').to_a if config.numeric
|
40
|
+
@characters_set += %w(! @ # $ % ^ & * _ +) if config.symbol
|
41
|
+
remove_ambiguous_characters
|
42
|
+
end
|
43
|
+
|
44
|
+
def remove_ambiguous_characters
|
45
|
+
@characters_set -= %w(i o O 1 l 0 I)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module PasswordListGenerator
|
2
|
+
class Password
|
3
|
+
attr_accessor :password, :config
|
4
|
+
|
5
|
+
def initialize(password, config)
|
6
|
+
@password = password
|
7
|
+
@config = config
|
8
|
+
end
|
9
|
+
|
10
|
+
def valid?
|
11
|
+
has_special? and has_numeric? and has_lowercase? and has_uppercase? and correct_length?
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
password
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def has_special?
|
21
|
+
config.symbol ? /\W/ === password : true
|
22
|
+
end
|
23
|
+
|
24
|
+
def has_numeric?
|
25
|
+
config.numeric ? /\d/ === password : true
|
26
|
+
end
|
27
|
+
|
28
|
+
def has_lowercase?
|
29
|
+
/[a-z]/ === password
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_uppercase?
|
33
|
+
config.uppercase ? /[A-Z]/ === password : true
|
34
|
+
end
|
35
|
+
|
36
|
+
def correct_length?
|
37
|
+
password.size >= config.min and password.size <= config.max
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: password_list_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephane Liu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Generate a list of passwords from command line with options for length
|
14
|
+
and complexity into a file of your choice.
|
15
|
+
email: sliu@sjliu.com
|
16
|
+
executables:
|
17
|
+
- pwgen
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/password_list_generator/password.rb
|
22
|
+
- lib/password_list_generator/generator.rb
|
23
|
+
- bin/pwgen
|
24
|
+
homepage: https://github.com/stephaneliu/password_generator
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.0.6
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Generate list of passwords easily from command line
|
48
|
+
test_files: []
|