simple-password-gen 0.1.5 → 0.2.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile.lock +17 -0
- data/README.rdoc +20 -18
- data/Rakefile +1 -1
- data/bin/simple-password-gen +31 -17
- data/lib/simple-password-gen.rb +74 -35
- data/lib/simple-password-gen/version.rb +1 -6
- data/simple-password-gen.gemspec +1 -8
- metadata +26 -56
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 264fcd0e6c9a3ebe6a356ce5c1a03575308345d8
|
4
|
+
data.tar.gz: 6a807e047ca5d8cefba002910bc66290bc82e710
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d04aa3bd25eae3ce66a17316ffecb1acc6a1158cae226fdf182f7f4410bc9d183eb87deee5f09dc9a7cd56c0906e0a63684492561560c0e26f03d0407dceda7d
|
7
|
+
data.tar.gz: f9b0a10e01cc866c6c2847916d5827ba76e78ef8666c7d1a38f13fe326df0c6035f81c7565140582f17acc9bd322d955a8c147bd6013818130c6f6b7d34dd7a5
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
data/README.rdoc
CHANGED
@@ -1,40 +1,42 @@
|
|
1
1
|
== Simple Password Generator
|
2
2
|
|
3
|
-
This class will generate either a
|
3
|
+
This class will generate either a pronounceable or complete random
|
4
4
|
password.
|
5
5
|
|
6
6
|
== Installation
|
7
7
|
|
8
8
|
Simply install the generator with Rubygems:
|
9
9
|
|
10
|
-
$ gem install simple-password-
|
10
|
+
$ gem install simple-password-gen
|
11
11
|
|
12
12
|
== Example
|
13
13
|
|
14
|
-
You may +require+ this file and generate some
|
14
|
+
You may +require+ this file and generate some passwords, like:
|
15
15
|
|
16
|
-
require 'simple-password-
|
17
|
-
puts Password.
|
18
|
-
puts Password.random(4)
|
19
|
-
pw = Password.new (1..10)
|
20
|
-
pw.
|
21
|
-
pw.
|
22
|
-
pw.random
|
16
|
+
require 'simple-password-gen'
|
17
|
+
puts Password.pronounceable # => "nduslihefrash"
|
18
|
+
puts Password.random(4) # => "w'ds"
|
19
|
+
pw = Password.new (1..10) # => #<Password:0x9678514 ...>
|
20
|
+
pw.pronounceable # => "t"
|
21
|
+
pw.pronounceable # => "vostyhish"
|
22
|
+
pw.random # => "8+a"
|
23
23
|
...
|
24
24
|
|
25
25
|
== Synopsis
|
26
26
|
|
27
|
-
Alternatively, you may simply run this file as
|
27
|
+
Alternatively, you may simply run this file as command line application:
|
28
28
|
|
29
|
-
$ simple-password-
|
30
|
-
simple-password-
|
31
|
-
Generates <
|
32
|
-
Will fail if
|
33
|
-
Defaults:
|
29
|
+
$ simple-password-gen -h
|
30
|
+
simple-password-gen [--length/-l LEN] [--number/-n NUM]
|
31
|
+
Generates <NUM> password(s) with appox. length <LEN>.
|
32
|
+
Will fail if NUM is less than 1 or LEN is less than 5.
|
33
|
+
Defaults: LEN=10, NUM=3
|
34
34
|
|
35
|
-
== Author
|
35
|
+
== Author and Contributors
|
36
36
|
|
37
|
-
Dominik Menke, <tt>
|
37
|
+
Written by Dominik Menke, <tt>dominik(dot)menke(at)gmail(dot)com</tt>
|
38
|
+
|
39
|
+
Some typo fixes by @tanraya (Andrew).
|
38
40
|
|
39
41
|
== License
|
40
42
|
|
data/Rakefile
CHANGED
data/bin/simple-password-gen
CHANGED
@@ -8,18 +8,18 @@ require 'simple-password-gen'
|
|
8
8
|
length = (9..11)
|
9
9
|
number = 3
|
10
10
|
GetoptLong.new(
|
11
|
-
[
|
12
|
-
[
|
13
|
-
[
|
11
|
+
['--length', '-l', GetoptLong::REQUIRED_ARGUMENT],
|
12
|
+
['--number', '-n', GetoptLong::REQUIRED_ARGUMENT],
|
13
|
+
['--help', '-h', GetoptLong::NO_ARGUMENT]
|
14
14
|
).each do |opt,arg|
|
15
15
|
case opt
|
16
16
|
when '--length'
|
17
17
|
l = arg.to_i
|
18
|
-
|
19
|
-
if length.begin < 5
|
18
|
+
if l < 5
|
20
19
|
puts "Srsly?"
|
21
20
|
exit 1
|
22
21
|
end
|
22
|
+
length = Range.new(l - 1, l + 1)
|
23
23
|
when '--number'
|
24
24
|
number = arg.to_i
|
25
25
|
if number < 1
|
@@ -27,20 +27,34 @@ GetoptLong.new(
|
|
27
27
|
exit 1
|
28
28
|
end
|
29
29
|
when '--help'
|
30
|
-
puts "#{$0} [--length/-l
|
31
|
-
puts "\tGenerates <
|
32
|
-
puts "\tWill fail if
|
33
|
-
puts "\tDefaults:
|
30
|
+
puts "#{$0} [--length/-l LEN] [--number/-n NUM]"
|
31
|
+
puts "\tGenerates <NUM> password(s) with appox. length <LEN>."
|
32
|
+
puts "\tWill fail if NUM is less than 1 or LEN is less than 5."
|
33
|
+
puts "\tDefaults: LEN=10, NUM=3"
|
34
34
|
exit
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
38
|
+
columns = {
|
39
|
+
pronounceable: "Pronounceable",
|
40
|
+
random: "Random",
|
41
|
+
urlsafe: "URL safe",
|
42
|
+
}
|
43
|
+
|
44
|
+
generator = Password.new(length)
|
45
|
+
header = columns.values
|
46
|
+
passwords = (0...number).map { columns.keys.map{|k| generator.send(k) } }
|
47
|
+
markup = " %*s | %*s | %*s "
|
48
|
+
|
49
|
+
widths = passwords.each_with_object(header.map(&:size)) {|pws, max|
|
50
|
+
(0...max.size).each {|i|
|
51
|
+
max[i] = pws[i].size if pws[i].size > max[i]
|
52
|
+
}
|
53
|
+
}.map{|w| -w }
|
54
|
+
|
55
|
+
puts markup % widths.zip(header).flatten
|
56
|
+
print "-", widths.map{|w| "-" * -w }.join("--+--"), "-\n"
|
57
|
+
|
58
|
+
passwords.each do |list|
|
59
|
+
puts markup % widths.zip(list).flatten
|
46
60
|
end
|
data/lib/simple-password-gen.rb
CHANGED
@@ -1,58 +1,97 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
# A simple Password generator. Central parts are based on
|
4
|
-
# http://snippets.dzone.com/posts/show/2137
|
3
|
+
# A simple Password generator. Central parts are based on a DZone snippet and its comments:
|
4
|
+
# https://web.archive.org/web/20090204082442/http://snippets.dzone.com/posts/show/2137
|
5
5
|
class Password
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
module CharacterSets
|
7
|
+
SAFE_CHARS = ("A".."Z").to_a | ("a".."z").to_a | ("0".."9").to_a | "-_.,;+!*()[]{}|~^<>\"'$=".split(//)
|
8
|
+
URL_UNSAFE = "#%/:@&?".split(//)
|
9
|
+
LOOKALIKE = "|io01lO".split(//)
|
10
|
+
|
11
|
+
ALL_CHARS = SAFE_CHARS | URL_UNSAFE
|
12
|
+
URL_SAFE = SAFE_CHARS
|
13
|
+
VISUAL_SAFE = SAFE_CHARS - LOOKALIKE
|
14
|
+
|
15
|
+
CONSONANTS = %w( b c d f g h j k l m n p r s t v w x z)
|
16
|
+
VOWELS = %w(a e i o u y)
|
17
|
+
COMPOUND = CONSONANTS | %w(ch cr fr nd ng nk nt ph pr qu rd sch sh sl sp st th tr)
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
# default length range value for new password generator instances
|
22
|
+
DEFAULT_LENGTH = 8..12
|
23
|
+
|
24
|
+
# the possible length values
|
25
|
+
attr_reader :length
|
12
26
|
|
13
27
|
# Creates a new password generator. The length +len+ might be an
|
14
|
-
# +Integer+ or a +Range+.
|
15
|
-
def initialize
|
16
|
-
|
17
|
-
@length = Range.new(len-1, len+1)
|
18
|
-
elsif len.is_a? Range
|
19
|
-
@length = len
|
20
|
-
else
|
21
|
-
raise ArgumentException, "Length is neither an Integer nor a Range."
|
22
|
-
end
|
28
|
+
# +Integer+, an +Array+ or a +Range+.
|
29
|
+
def initialize(len = DEFAULT_LENGTH)
|
30
|
+
coerce_length! len
|
23
31
|
end
|
24
32
|
|
25
33
|
class << self
|
26
|
-
#
|
27
|
-
def pronounceable
|
28
|
-
|
34
|
+
# Short-hand for +#new.pronouncable+.
|
35
|
+
def pronounceable(len = DEFAULT_LENGTH)
|
36
|
+
new(len).pronounceable
|
29
37
|
end
|
30
38
|
|
31
|
-
#
|
32
|
-
def random
|
33
|
-
|
39
|
+
# Short-hand for +#new.random+.
|
40
|
+
def random(len = DEFAULT_LENGTH)
|
41
|
+
new(len).random
|
42
|
+
end
|
43
|
+
|
44
|
+
# Short-hand for +#new.urlsafe+.
|
45
|
+
def urlsafe(len = DEFAULT_LENGTH)
|
46
|
+
new(len).urlsafe
|
34
47
|
end
|
35
48
|
end
|
36
49
|
|
37
50
|
# Generates a pronounceable password.
|
38
51
|
def pronounceable
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
pw
|
52
|
+
set = rand > 0.5
|
53
|
+
|
54
|
+
build_password {
|
55
|
+
set = !set
|
56
|
+
set ? CharacterSets::CONSONANTS.sample : CharacterSets::VOWELS.sample
|
57
|
+
}
|
46
58
|
end
|
47
59
|
|
48
60
|
# Unlike #pronounceable, this does not ensure the pronounceability and
|
49
61
|
# will include some special characters, but will exclude "unfriendly"
|
50
62
|
# characters (like +0+, +O+).
|
51
63
|
def random
|
52
|
-
|
53
|
-
(1..size).collect do |a|
|
54
|
-
CHARS[rand(CHARS.size)]
|
55
|
-
end.join ''
|
64
|
+
build_password { CharacterSets::ALL_CHARS.sample }
|
56
65
|
end
|
57
|
-
end
|
58
66
|
|
67
|
+
# Generates a passwort suitable for usage in HTTP(S) URLs, i.e. the
|
68
|
+
# following characters are excluded: +:@/+.
|
69
|
+
def urlsafe
|
70
|
+
build_password { CharacterSets::URL_SAFE.sample }
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def build_password
|
76
|
+
size, pw = length.sample, ''
|
77
|
+
while pw.size <= size
|
78
|
+
pw << yield
|
79
|
+
end
|
80
|
+
pw
|
81
|
+
end
|
82
|
+
|
83
|
+
def coerce_length!(len)
|
84
|
+
length = case len
|
85
|
+
when NilClass then DEFAULT_LENGTH.to_a
|
86
|
+
when Integer then (len-1 .. len+1).to_a
|
87
|
+
when Range then len.to_a
|
88
|
+
when Array then len
|
89
|
+
else raise ArgumentException, "Length is neither an Integer nor a Range (got #{len.class})."
|
90
|
+
end.select{|i| i.is_a?(Integer) && i > 0 }.sort.uniq
|
91
|
+
|
92
|
+
raise TypeError, "Cannot coerce #{len} (#{len.class}) into Password length" if length.empty?
|
93
|
+
|
94
|
+
@length = length
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/simple-password-gen.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
$:.push File.expand_path("../lib", __FILE__)
|
3
2
|
require "simple-password-gen/version"
|
4
3
|
|
@@ -7,18 +6,12 @@ Gem::Specification.new do |s|
|
|
7
6
|
s.version = Password::VERSION
|
8
7
|
s.platform = Gem::Platform::RUBY
|
9
8
|
s.authors = ["Dominik Menke"]
|
10
|
-
s.email = ["
|
9
|
+
s.email = ["dominik.menke@gmail.com"]
|
11
10
|
s.homepage = "http://github.org/dmke/simple-password-gen"
|
12
11
|
s.summary = %q{Simple password generator to create pronounceable or random passowords.}
|
13
|
-
s.description = s.summary + "\n\nThis gem comes with an executable and might also be required."
|
14
12
|
|
15
13
|
s.files = `git ls-files`.split("\n")
|
16
14
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
16
|
s.require_paths = ["lib"]
|
19
|
-
|
20
|
-
s.rdoc_options << '--title' << 'Simple Password Generator' <<
|
21
|
-
'--main' << 'README.rdoc' << '--show-hash' <<
|
22
|
-
`git ls-files -- lib/*`.split("\n") <<
|
23
|
-
'README.rdoc' << 'LICENSE'
|
24
17
|
end
|
metadata
CHANGED
@@ -1,38 +1,26 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-password-gen
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 5
|
9
|
-
version: 0.1.5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0.alpha
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Dominik Menke
|
13
8
|
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2011-01-21 00:00:00 +01:00
|
18
|
-
default_executable:
|
11
|
+
date: 2016-06-06 00:00:00.000000000 Z
|
19
12
|
dependencies: []
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
This gem comes with an executable and might also be required.
|
25
|
-
email:
|
26
|
-
- dmke@tzi.de
|
27
|
-
executables:
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- dominik.menke@gmail.com
|
16
|
+
executables:
|
28
17
|
- simple-password-gen
|
29
18
|
extensions: []
|
30
|
-
|
31
19
|
extra_rdoc_files: []
|
32
|
-
|
33
|
-
|
34
|
-
- .gitignore
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
35
22
|
- Gemfile
|
23
|
+
- Gemfile.lock
|
36
24
|
- LICENSE
|
37
25
|
- README.rdoc
|
38
26
|
- Rakefile
|
@@ -40,45 +28,27 @@ files:
|
|
40
28
|
- lib/simple-password-gen.rb
|
41
29
|
- lib/simple-password-gen/version.rb
|
42
30
|
- simple-password-gen.gemspec
|
43
|
-
has_rdoc: true
|
44
31
|
homepage: http://github.org/dmke/simple-password-gen
|
45
32
|
licenses: []
|
46
|
-
|
33
|
+
metadata: {}
|
47
34
|
post_install_message:
|
48
|
-
rdoc_options:
|
49
|
-
|
50
|
-
- Simple Password Generator
|
51
|
-
- --main
|
52
|
-
- README.rdoc
|
53
|
-
- --show-hash
|
54
|
-
- - lib/simple-password-gen.rb
|
55
|
-
- lib/simple-password-gen/version.rb
|
56
|
-
- README.rdoc
|
57
|
-
- LICENSE
|
58
|
-
require_paths:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
59
37
|
- lib
|
60
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
-
|
62
|
-
requirements:
|
63
|
-
- - ">="
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
segments:
|
66
|
-
- 0
|
67
|
-
version: "0"
|
68
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
|
-
requirements:
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
71
40
|
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
|
75
|
-
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.3.1
|
76
48
|
requirements: []
|
77
|
-
|
78
49
|
rubyforge_project:
|
79
|
-
rubygems_version:
|
50
|
+
rubygems_version: 2.5.1
|
80
51
|
signing_key:
|
81
|
-
specification_version:
|
52
|
+
specification_version: 4
|
82
53
|
summary: Simple password generator to create pronounceable or random passowords.
|
83
54
|
test_files: []
|
84
|
-
|