simple-password-gen 0.1.3
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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE +28 -0
- data/README.rdoc +34 -0
- data/Rakefile +8 -0
- data/bin/simple-password-gen +46 -0
- data/lib/simple-password-gen.rb +58 -0
- data/lib/simple-password-gen/version.rb +8 -0
- data/simple-password-gen.gemspec +21 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Copyright 2010 Dominik Menke. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions are
|
5
|
+
met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright
|
8
|
+
notice, this list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY DOMINIK MENKE ``AS IS'' AND ANY EXPRESS OR
|
15
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
16
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
DISCLAIMED. IN NO EVENT SHALL DOMINIK MENKE OR CONTRIBUTORS BE LIABLE
|
18
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
19
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
20
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
21
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
22
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
23
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
24
|
+
THE POSSIBILITY OF SUCH DAMAGE.
|
25
|
+
|
26
|
+
The views and conclusions contained in the software and documentation
|
27
|
+
are those of the authors and should not be interpreted as representing
|
28
|
+
official policies, either expressed or implied, of Dominik Menke.
|
data/README.rdoc
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
== Simple password generator
|
2
|
+
|
3
|
+
This class will generate either a pronouncable or complete random
|
4
|
+
password.
|
5
|
+
|
6
|
+
== Example
|
7
|
+
|
8
|
+
You may +require+ this file and generate some password, like:
|
9
|
+
|
10
|
+
require '.../passwd-gen.rb'
|
11
|
+
puts Password.pronouncable # => "nduslihefrash"
|
12
|
+
puts Password.random(4) # => "w'ds"
|
13
|
+
pw = Password.new (1..10) # => #<Password:0x9678514 ...>
|
14
|
+
pw.pronouncable # => "t"
|
15
|
+
pw.pronouncable # => "vostyhish"
|
16
|
+
pw.random # => "8+a"
|
17
|
+
...
|
18
|
+
|
19
|
+
== Synopsis
|
20
|
+
|
21
|
+
Alternatively, you may simply run this file as commandline application:
|
22
|
+
|
23
|
+
$ ruby passwd-gen.rb -h
|
24
|
+
passwd-gen.rb [--length/-l len] [--number/-n num]
|
25
|
+
Generates <n> password(s) with appox. length <len>.
|
26
|
+
Will fail if n is less than 1 or len is less than 5.
|
27
|
+
Defaults: length=10, number=3
|
28
|
+
|
29
|
+
== Author
|
30
|
+
Dominik Menke, <tt>dmke(at)tzi(dot)org</tt>
|
31
|
+
|
32
|
+
== License
|
33
|
+
Simplified BSD License
|
34
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'getoptlong'
|
6
|
+
require 'simple-password-gen'
|
7
|
+
|
8
|
+
length = (9..11)
|
9
|
+
number = 3
|
10
|
+
GetoptLong.new(
|
11
|
+
[ '--length', '-l', GetoptLong::REQUIRED_ARGUMENT ],
|
12
|
+
[ '--number', '-n', GetoptLong::REQUIRED_ARGUMENT ],
|
13
|
+
[ '--help', '-h', GetoptLong::NO_ARGUMENT ]
|
14
|
+
).each do |opt,arg|
|
15
|
+
case opt
|
16
|
+
when '--length'
|
17
|
+
l = arg.to_i
|
18
|
+
length = Range.new(l - 1, l + 1)
|
19
|
+
if length.begin < 5
|
20
|
+
puts "Srsly?"
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
when '--number'
|
24
|
+
number = arg.to_i
|
25
|
+
if number < 1
|
26
|
+
puts "Srsly?"
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
when '--help'
|
30
|
+
puts "#{$0} [--length/-l len] [--number/-n num]"
|
31
|
+
puts "\tGenerates <n> password(s) with appox. length <len>."
|
32
|
+
puts "\tWill fail if n is less than 1 or len is less than 5."
|
33
|
+
puts "\tDefaults: length=10, number=3"
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# so, finally:
|
39
|
+
row = '%%-%ds | %%s' % length.begin
|
40
|
+
row = '%-20s | %s' if length.begin < 20
|
41
|
+
puts row % ['Pronounceable', 'Random']
|
42
|
+
puts '=' * 80
|
43
|
+
pw = Password.new(length)
|
44
|
+
number.times do
|
45
|
+
puts row % [pw.pronounceable, pw.random]
|
46
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# A simple Password generator. Central parts are based on
|
4
|
+
# http://snippets.dzone.com/posts/show/2137 and comments.
|
5
|
+
class Password
|
6
|
+
# consonantes and pronounceable combinations with vowels
|
7
|
+
CONSONANTS = %w(b c d f g h j k l m n p qu r s t v w x z ch cr fr nd ng nk nt ph pr rd sch sh sl sp st th tr)
|
8
|
+
# vowels and sound-alike +y+
|
9
|
+
VOWELS = %w(a e i o u y)
|
10
|
+
# some characters
|
11
|
+
CHARS = (('a'..'z').to_a + ('0'..'9').to_a + "%&/()[]!\"§$,.-;:_#'+*?".split(//u)) - "io01l0".split(//u)
|
12
|
+
|
13
|
+
# Creates a new password generator. The length +len+ might be an
|
14
|
+
# +Integer+ or a +Range+.
|
15
|
+
def initialize len = (8..12)
|
16
|
+
if len.is_a? Integer
|
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
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
# Similar to #pronounceable, this generates a pronounceable password.
|
27
|
+
def pronounceable len = (8..12)
|
28
|
+
self.new(len).pronounceable
|
29
|
+
end
|
30
|
+
|
31
|
+
# Similar to #random, this generates a random password.
|
32
|
+
def random len = (8..12)
|
33
|
+
self.new(len).random
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generates a pronounceable password.
|
38
|
+
def pronounceable
|
39
|
+
size = @length.to_a[rand(@length.count)] - 2
|
40
|
+
f, pw = true, ''
|
41
|
+
size.times do
|
42
|
+
pw << (f ? CONSONANTS[rand * CONSONANTS.size] : VOWELS[rand * VOWELS.size])
|
43
|
+
f = !f
|
44
|
+
end
|
45
|
+
pw
|
46
|
+
end
|
47
|
+
|
48
|
+
# Unlike #pronounceable, this does not ensure the pronounceability and
|
49
|
+
# will include some special characters, but will exclude "unfriendly"
|
50
|
+
# characters (like +0+, +O+).
|
51
|
+
def random
|
52
|
+
size = @length.to_a[rand(@length.count)]
|
53
|
+
(1..size).collect do |a|
|
54
|
+
CHARS[rand(CHARS.size)]
|
55
|
+
end.join ''
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "simple-password-gen/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "simple-password-gen"
|
7
|
+
s.version = Password::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Dominik Menke"]
|
10
|
+
s.email = ["dmke@tzi.de"]
|
11
|
+
s.homepage = "http://github.org/dmke/simple-password-gen"
|
12
|
+
s.summary = %q{Simple password generator to create pronounceable or random passowords.}
|
13
|
+
s.description = %q{This gem comes with an executable and might also be required.}
|
14
|
+
|
15
|
+
s.rubyforge_project = ""
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-password-gen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dominik Menke
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-19 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: This gem comes with an executable and might also be required.
|
22
|
+
email:
|
23
|
+
- dmke@tzi.de
|
24
|
+
executables:
|
25
|
+
- simple-password-gen
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- LICENSE
|
34
|
+
- README.rdoc
|
35
|
+
- Rakefile
|
36
|
+
- bin/simple-password-gen
|
37
|
+
- lib/simple-password-gen.rb
|
38
|
+
- lib/simple-password-gen/version.rb
|
39
|
+
- simple-password-gen.gemspec
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.org/dmke/simple-password-gen
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: ""
|
68
|
+
rubygems_version: 1.3.7
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Simple password generator to create pronounceable or random passowords.
|
72
|
+
test_files: []
|
73
|
+
|