jameswilding-passgen 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/passgen +22 -26
- data/lib/passgen.rb +4 -2
- data/lib/passgen/cli.rb +39 -0
- data/lib/passgen/memorable.rb +54 -0
- metadata +6 -4
data/bin/passgen
CHANGED
@@ -1,36 +1,32 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'optparse'
|
3
|
-
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'passgen'
|
7
|
-
rescue LoadError
|
8
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'passgen')
|
9
|
-
end
|
3
|
+
require 'rubygems'
|
4
|
+
require 'passgen'
|
10
5
|
|
11
6
|
options = {}
|
12
7
|
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
begin
|
9
|
+
# Command line switches
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: passgen [options]"
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
opts.on('-H', '--hex', 'Output both plain text and hexdigest-encrypted versions of the password') do |hex|
|
22
|
-
options[:hex] = hex
|
23
|
-
end
|
24
|
-
|
25
|
-
end.parse!
|
13
|
+
opts.on('-l', '--length N', Integer, 'Make a password of length N (default is 10)') do |n|
|
14
|
+
options[:length] = n
|
15
|
+
end
|
26
16
|
|
27
|
-
|
28
|
-
|
17
|
+
opts.on('--memorable', 'Create a more memorable (but less secure) password using real words. Ignores --length') do
|
18
|
+
options[:memorable] = true
|
19
|
+
end
|
29
20
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
21
|
+
opts.on('-H', '--hexed', 'Output both plain text and hexdigest-encrypted versions of the password') do
|
22
|
+
options[:hex] = true
|
23
|
+
end
|
24
|
+
|
25
|
+
end.parse!
|
26
|
+
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument
|
27
|
+
puts "Usage: passgen [--length N | --memorable] [--hexed]"
|
28
|
+
puts
|
29
|
+
puts "Try passgen --help for more information."
|
34
30
|
else
|
35
|
-
|
31
|
+
PassGen::CLI.execute(options)
|
36
32
|
end
|
data/lib/passgen.rb
CHANGED
data/lib/passgen/cli.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module PassGen
|
2
|
+
module CLI
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def execute(options)
|
6
|
+
@@options = options
|
7
|
+
|
8
|
+
if options[:hex]
|
9
|
+
execute_with_hexing
|
10
|
+
else
|
11
|
+
execute_without_hexing
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def execute_without_hexing
|
17
|
+
say normal_or_memorable_password
|
18
|
+
end
|
19
|
+
|
20
|
+
def execute_with_hexing
|
21
|
+
password = normal_or_memorable_password
|
22
|
+
say "plain: #{password}", "hexed: #{password.hexed}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def normal_or_memorable_password
|
26
|
+
if @@options[:memorable]
|
27
|
+
PassGen::Memorable::Password.new
|
28
|
+
else
|
29
|
+
PassGen::Password.new(@@options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def say(*things)
|
34
|
+
STDOUT.puts things.join("\n")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
module PassGen
|
4
|
+
module Memorable
|
5
|
+
class Password < String
|
6
|
+
|
7
|
+
SYMBOLS = %w(% & $ £ @ !)
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@dictionary = Dictionary.new
|
11
|
+
super(random_words_symbols_and_numbers)
|
12
|
+
end
|
13
|
+
|
14
|
+
def hexed
|
15
|
+
Digest::SHA1.hexdigest(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def random_words_symbols_and_numbers
|
20
|
+
(random_words.join random_symbols_and_numbers).downcase
|
21
|
+
end
|
22
|
+
|
23
|
+
def random_words
|
24
|
+
[@dictionary.random, @dictionary.random]
|
25
|
+
end
|
26
|
+
|
27
|
+
def random_symbols_and_numbers
|
28
|
+
SYMBOLS[rand(SYMBOLS.length)] + random_numbers
|
29
|
+
end
|
30
|
+
|
31
|
+
def random_numbers
|
32
|
+
rand(10).to_s + rand(10).to_s
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Inspired by http://stephencelis.com/2009/03/29/whats-the-password-haddock.html
|
37
|
+
class Dictionary
|
38
|
+
|
39
|
+
PATHS = %w(/usr/share/dict/words /usr/share/words)
|
40
|
+
|
41
|
+
def random
|
42
|
+
words = get_words
|
43
|
+
words[rand(words.length)].chomp
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_words
|
47
|
+
File.readlines(PATHS.first).select { |word| word.length < 6 }
|
48
|
+
rescue Errno::ENOENT
|
49
|
+
File.readlines(PATHS.last).select { |word| word.length < 6 }
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jameswilding-passgen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Wilding
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-17 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description: Passgen
|
16
|
+
description: Passgen generates random, alphanumeric passwords of up to twenty characters, which can be made memorable if you don't mind the security tradeoff.
|
17
17
|
email:
|
18
18
|
executables:
|
19
19
|
- passgen
|
@@ -24,6 +24,8 @@ extra_rdoc_files: []
|
|
24
24
|
files:
|
25
25
|
- bin/passgen
|
26
26
|
- lib/passgen.rb
|
27
|
+
- lib/passgen/cli.rb
|
28
|
+
- lib/passgen/memorable.rb
|
27
29
|
- lib/passgen/password.rb
|
28
30
|
has_rdoc: false
|
29
31
|
homepage:
|
@@ -50,6 +52,6 @@ rubyforge_project:
|
|
50
52
|
rubygems_version: 1.2.0
|
51
53
|
signing_key:
|
52
54
|
specification_version: 2
|
53
|
-
summary: random password generator
|
55
|
+
summary: random password generator with command-line utility
|
54
56
|
test_files: []
|
55
57
|
|