cryptice-passgen 0.1.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.
- data/CHANGELOG +0 -0
- data/Manifest +8 -0
- data/README.rdoc +121 -0
- data/Rakefile +15 -0
- data/init.rb +2 -0
- data/lib/passgen.rb +87 -0
- data/passgen.gemspec +31 -0
- data/spec/passgen_spec.rb +96 -0
- metadata +67 -0
data/CHANGELOG
ADDED
File without changes
|
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
= Passgen
|
2
|
+
|
3
|
+
Ruby gem for generating passwords quickly and easily. Although it is
|
4
|
+
suitable for use within Rails it has no Rails dependencies and can be used in
|
5
|
+
non-Rails applications as well.
|
6
|
+
|
7
|
+
== Install
|
8
|
+
|
9
|
+
gem install cryptice-passgen --source http://gems.github.com
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
The usage could not be easier. Just require and call the generate method:
|
14
|
+
|
15
|
+
>> require 'passgen'
|
16
|
+
>> Passgen::generate
|
17
|
+
=> "zLWCeS3xC9"
|
18
|
+
|
19
|
+
== Examples
|
20
|
+
|
21
|
+
>> Passgen::generate
|
22
|
+
=> "zLWCeS3xC9"
|
23
|
+
|
24
|
+
>> Passgen::generate(:length => 20)
|
25
|
+
=> "6lCcHvkuEW6OuzAtkoAs"
|
26
|
+
|
27
|
+
>> Passgen::generate(:symbols => true)
|
28
|
+
=> "gr)$6bIym1"
|
29
|
+
|
30
|
+
>> Passgen::generate(:lowercase => :only)
|
31
|
+
=> "ysbwuxbcea"
|
32
|
+
|
33
|
+
>> Passgen::generate(:number => 3)
|
34
|
+
=> ["REdOigTkdI", "PQu8DsV9WZ", "qptKLbw8YQ"]
|
35
|
+
|
36
|
+
>> Passgen::generate(:seed => 5)
|
37
|
+
=> "JoV9M2qjiK"
|
38
|
+
>> Passgen::generate(:seed => 5) # Will generate same password again
|
39
|
+
=> "JoV9M2qjiK"
|
40
|
+
|
41
|
+
>> Passgen::generate(:seed => :default) # Will set random seed...
|
42
|
+
=> "SI8QDBdV98"
|
43
|
+
>> Passgen::generate(:seed => :default) # and hence give different password
|
44
|
+
=> "tHHU5HLBAn"
|
45
|
+
|
46
|
+
== Options:
|
47
|
+
|
48
|
+
=== :lowercase => true/false/:only
|
49
|
+
* true - Use lowercase letters in the generated password.
|
50
|
+
* false - Do not use lowercase letters in the generated password.
|
51
|
+
* :only - Only use lowercase letters in the generated password.
|
52
|
+
|
53
|
+
=== :uppercase => true/false/:only
|
54
|
+
* true - Use uppercase letters in the generated password.
|
55
|
+
* false - Do not use uppercase letters in the generated password.
|
56
|
+
* :only - Only use uppercase letters in the generated password.
|
57
|
+
|
58
|
+
=== :digits => true/false/:only
|
59
|
+
* true - Use digits in the generated password.
|
60
|
+
* false - Do not use digits in the generated password.
|
61
|
+
* :only - Only use digits in the generated password.
|
62
|
+
|
63
|
+
=== :symbols => true/false/:only/:list
|
64
|
+
* true - Use symbols in the generated password.
|
65
|
+
* false - Do not use symbols in the generated password.
|
66
|
+
* :only - Only use symbols in the generated password.
|
67
|
+
* :list - A string with the symbols to use. Not implemented yet.
|
68
|
+
|
69
|
+
=== :pronounceable => true/false
|
70
|
+
Not implmented yet.
|
71
|
+
|
72
|
+
=== :number => integer
|
73
|
+
Number of passwords to generate. If >1 the result is an Array.
|
74
|
+
|
75
|
+
=== :length => integer/range
|
76
|
+
The number of characters in the generated passwords. A range results in passwords
|
77
|
+
lengths within the given range.
|
78
|
+
|
79
|
+
=== :seed => integer/:default
|
80
|
+
Set the srand seed to the given integer prior to generating the passwords.
|
81
|
+
|
82
|
+
=== Default values:
|
83
|
+
|
84
|
+
:lowercase => true
|
85
|
+
|
86
|
+
:uppercase => true
|
87
|
+
|
88
|
+
:digits => true
|
89
|
+
|
90
|
+
:symbols => false
|
91
|
+
|
92
|
+
:pronounceable => Not implemented yet.
|
93
|
+
|
94
|
+
:number => 1
|
95
|
+
|
96
|
+
:length => 10
|
97
|
+
|
98
|
+
:seed => nil
|
99
|
+
|
100
|
+
== Copyright and license
|
101
|
+
|
102
|
+
Copyright (c) 2009 Erik Lindblad
|
103
|
+
|
104
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
105
|
+
a copy of this software and associated documentation files (the
|
106
|
+
"Software"), to deal in the Software without restriction, including
|
107
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
108
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
109
|
+
permit persons to whom the Software is furnished to do so, subject to
|
110
|
+
the following conditions:
|
111
|
+
|
112
|
+
The above copyright notice and this permission notice shall be
|
113
|
+
included in all copies or substantial portions of the Software.
|
114
|
+
|
115
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
116
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
117
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
118
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
119
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
120
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
121
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Rakefile
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'echoe'
|
5
|
+
|
6
|
+
Echoe.new('passgen', '0.1.1') do |p|
|
7
|
+
p.description = "A password generation gem for Ruby and Rails applications."
|
8
|
+
p.url = "http://github.com/cryptice/passgen"
|
9
|
+
p.author = "Erik Lindblad"
|
10
|
+
p.email = "eriklindblad3@gmail.com"
|
11
|
+
p.ignore_pattern = ["tmp/*", "script/*", "nbproject/*"]
|
12
|
+
p.development_dependencies = []
|
13
|
+
end
|
14
|
+
|
15
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/init.rb
ADDED
data/lib/passgen.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require "digest"
|
2
|
+
|
3
|
+
module Passgen
|
4
|
+
|
5
|
+
DEFAULT_PARAMS = {
|
6
|
+
:number => 1,
|
7
|
+
:length => 10,
|
8
|
+
:lowercase => true,
|
9
|
+
:uppercase => true,
|
10
|
+
:digits => true,
|
11
|
+
:symbols => false
|
12
|
+
}
|
13
|
+
|
14
|
+
def self.generate(params={})
|
15
|
+
set_options(params)
|
16
|
+
tokens = valid_tokens
|
17
|
+
set_seed
|
18
|
+
|
19
|
+
if n == 1
|
20
|
+
generate_one(tokens)
|
21
|
+
else
|
22
|
+
Array.new(n) {|i| generate_one(tokens) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.generate_one(tokens)
|
27
|
+
Array.new(password_length) {tokens[rand(tokens.size)]}.join
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.set_seed
|
31
|
+
if @options[:seed]
|
32
|
+
if @options[:seed] == :default
|
33
|
+
srand(Digest::MD5.hexdigest("#{rand}#{Time.now}#{Process.object_id}").to_i(16))
|
34
|
+
else
|
35
|
+
srand(@options[:seed])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.password_length
|
41
|
+
if @options[:length].is_a?(Range)
|
42
|
+
tmp = @options[:length].to_a
|
43
|
+
tmp[rand(tmp.size)]
|
44
|
+
else
|
45
|
+
@options[:length].to_i
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.n
|
50
|
+
@options[:number]
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.set_options(params)
|
54
|
+
if params[:lowercase] == :only
|
55
|
+
params[:uppercase] = false
|
56
|
+
params[:digits] = false
|
57
|
+
end
|
58
|
+
|
59
|
+
if params[:uppercase] == :only
|
60
|
+
params[:lowercase] = false
|
61
|
+
params[:digits] = false
|
62
|
+
end
|
63
|
+
|
64
|
+
if params[:digits] == :only
|
65
|
+
params[:lowercase] = false
|
66
|
+
params[:uppercase] = false
|
67
|
+
end
|
68
|
+
|
69
|
+
if params[:symbols] == :only
|
70
|
+
params[:lowercase] = false
|
71
|
+
params[:uppercase] = false
|
72
|
+
params[:digits] = false
|
73
|
+
params[:symbols] = true
|
74
|
+
end
|
75
|
+
|
76
|
+
@options = DEFAULT_PARAMS.merge(params)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.valid_tokens
|
80
|
+
tmp = []
|
81
|
+
tmp += ("a".."z").to_a if @options[:lowercase]
|
82
|
+
tmp += ("A".."Z").to_a if @options[:uppercase]
|
83
|
+
tmp += ("0".."9").to_a if @options[:digits]
|
84
|
+
tmp += %w{! @ # $ % & / ( ) + ? *} if @options[:symbols]
|
85
|
+
tmp
|
86
|
+
end
|
87
|
+
end
|
data/passgen.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{passgen}
|
5
|
+
s.version = "0.1.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Erik Lindblad"]
|
9
|
+
s.date = %q{2009-05-02}
|
10
|
+
s.description = %q{A password generation gem for Ruby and Rails applications.}
|
11
|
+
s.email = %q{eriklindblad3@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["lib/passgen.rb", "CHANGELOG", "README.rdoc"]
|
13
|
+
s.files = ["spec/passgen_spec.rb", "Rakefile", "Manifest", "lib/passgen.rb", "CHANGELOG", "init.rb", "passgen.gemspec", "README.rdoc"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/cryptice/passgen}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Passgen", "--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{passgen}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{A password generation gem for Ruby and Rails applications.}
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 2
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
else
|
28
|
+
end
|
29
|
+
else
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require "./lib/passgen"
|
2
|
+
|
3
|
+
describe "Using passgen" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
srand(2)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return password with default settings." do
|
10
|
+
Passgen::generate.should eql("OpTiwRslOh")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return password with uppercase chars only" do
|
14
|
+
Passgen::generate(:uppercase => :only).should eql("IPNIWLSLIH")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return password with lowercase chars only" do
|
18
|
+
Passgen::generate(:lowercase => :only).should eql("ipniwlslih")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return password with digits only" do
|
22
|
+
Passgen::generate(:digits => :only).should eql("8862872154")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return password with symbols only" do
|
26
|
+
Passgen::generate(:symbols => :only).should eql("))/*#*)(\#@")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return password with lowercase and uppercase chars only" do
|
30
|
+
Passgen::generate(:digits => false).should eql("OpTiwRslOh")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return password with lowercase and digit chars only" do
|
34
|
+
Passgen::generate(:uppercase => false).should eql("piwslh85lv")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return password with lowercase and symbol chars only" do
|
38
|
+
Passgen::generate(:uppercase => false, :digits => false, :symbols => true).should eql("piwslh)&lv")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return password with uppercase and digit chars only" do
|
42
|
+
Passgen::generate(:lowercase => false).should eql("PIWSLH85LV")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return password with uppercase and symbol chars only" do
|
46
|
+
Passgen::generate(:lowercase => false, :digits => false, :symbols => true).should eql("PIWSLH)&LV")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return password with digit and symbol chars only" do
|
50
|
+
Passgen::generate(:lowercase => false, :uppercase => false, :symbols => true).should eql("8&$8@)@872")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return password with lowercase, uppercase and digit chars only" do
|
54
|
+
Passgen::generate.should eql("OpTiwRslOh")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return password with lowercase, uppercase and symbol chars only" do
|
58
|
+
srand(3)
|
59
|
+
Passgen::generate(:digits => false, :symbols => true).should eql("Qy&d%iav+t")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return password with lowercase, digit and symbol chars only" do
|
63
|
+
srand(4)
|
64
|
+
Passgen::generate(:uppercase => false, :symbols => true).should eql("?fb%xij$+4")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return password with uppercase, digit and symbol chars only" do
|
68
|
+
srand(4)
|
69
|
+
Passgen::generate(:lowercase => false, :symbols => true).should eql("?FB%XIJ$+4")
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return given number of passwords in an Array" do
|
73
|
+
Passgen::generate(:number => 3).should eql(["OpTiwRslOh", "IXFlvVFAu8", "0LNdMeQRZN"])
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should return a password with given length" do
|
77
|
+
Passgen::generate(:length => 8).should eql("OpTiwRsl")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should return several passwords of variable length" do
|
81
|
+
Passgen::generate(:length => 3..12, :number => 2).should eql(["pTiwRslOhIX", "VFAu80LN"])
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should use given seed" do
|
85
|
+
pass1 = Passgen::generate(:seed => 5)
|
86
|
+
pass2 = Passgen::generate(:seed => 5)
|
87
|
+
pass1.should eql(pass2)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should set seed to Time.now + Process.id" do
|
91
|
+
pass1 = Passgen::generate(:seed => :default)
|
92
|
+
pass2 = Passgen::generate(:seed => :default)
|
93
|
+
pass1.should_not eql(pass2)
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cryptice-passgen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Erik Lindblad
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-02 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A password generation gem for Ruby and Rails applications.
|
17
|
+
email: eriklindblad3@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- lib/passgen.rb
|
24
|
+
- CHANGELOG
|
25
|
+
- README.rdoc
|
26
|
+
files:
|
27
|
+
- spec/passgen_spec.rb
|
28
|
+
- Rakefile
|
29
|
+
- Manifest
|
30
|
+
- lib/passgen.rb
|
31
|
+
- CHANGELOG
|
32
|
+
- init.rb
|
33
|
+
- passgen.gemspec
|
34
|
+
- README.rdoc
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/cryptice/passgen
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --line-numbers
|
40
|
+
- --inline-source
|
41
|
+
- --title
|
42
|
+
- Passgen
|
43
|
+
- --main
|
44
|
+
- README.rdoc
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "1.2"
|
58
|
+
version:
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project: passgen
|
62
|
+
rubygems_version: 1.2.0
|
63
|
+
signing_key:
|
64
|
+
specification_version: 2
|
65
|
+
summary: A password generation gem for Ruby and Rails applications.
|
66
|
+
test_files: []
|
67
|
+
|