dev-random-passwords 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d3d62e89fa2d720f4775a0b3d73aed3e52c0b41e
4
+ data.tar.gz: 0dd5b95dbbde4d59663f9df222fbdd65a3921436
5
+ SHA512:
6
+ metadata.gz: 311fa111d01e0ace33d78c3759ae2c61c9795d65d64b50b161f571d4f71ab9bca01eb55d3a9ad5ce6333359bc314fdb6b63d3b083bb505131af566d52dc54ed5
7
+ data.tar.gz: 38db336e907278907ee927e8f95b3e9fb696305dc400b2f9538d44f99af4361703383de2aea27a9a0b8aba1e33c1df689d4c61cf93a28a0187451cec404ca6f6
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dev-random-passwords.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ Copyright (c) 2014, Joel Smith
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of Trosic nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Dev-Random-Passwords
2
+
3
+ Passwords that need to be used long term and are randomly generated need more randomness than your standard random library. On Linux, Unix or OSX /dev/random can be used to create really secure passwords from random bytes. This gem provides an implementation to do just that.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dev-random-passwords'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dev-random-passwords
20
+
21
+ ## Usage
22
+ Require the gem
23
+
24
+ ```ruby
25
+ require 'dev-random-passwords'
26
+ ```
27
+
28
+ Set up a new instance
29
+ ```ruby
30
+ rpg = DevRandomPasswords::Generator.new
31
+ ```
32
+
33
+ Set some options for your password
34
+ ```ruby
35
+ rpg.set_options({'lowercase' => true, 'uppercase' => true, 'digits' => true, 'length' => 12, 'requirements' => {'digits' => true, 'uppercase' => true, 'lowercase' => true}})
36
+ ```
37
+
38
+ Generate a new password
39
+ ```ruby
40
+ rpg.generate
41
+ => "J0jhBM9dAPwk"
42
+ ```
43
+
44
+ Enjoy!
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it ( https://github.com/jbsmith86/dev-random-passwords/fork )
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dev-random-passwords/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dev-random-passwords"
8
+ spec.version = DevRandomPasswords::VERSION
9
+ spec.authors = ["Joel Smith"]
10
+ spec.email = ["joel@trosic.com"]
11
+ spec.summary = %q{Passwords that need to be used long term and are randomly generated need more randomness than your standard random library}
12
+ spec.description = %q{On Linux, Unix or OSX /dev/random can be used to create really secure passwords from random bytes. This gem provides an implementation to do just that.}
13
+ spec.homepage = "https://github.com/jbsmith86/dev-random-passwords"
14
+ spec.license = "BSD-3-Clause-Clear"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,147 @@
1
+ module DevRandomPasswords
2
+ class Generator
3
+
4
+ attr_accessor :charset
5
+ attr_accessor :char_length
6
+
7
+ LOWERCASE_CHARS = ('a'..'z').to_a.join("")
8
+ UPPERCASE_CHARS = ('A'..'Z').to_a.join("")
9
+ DIGITS = ('0'..'9').to_a.join("")
10
+ SPECIAL_CHARS = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
11
+
12
+ def initialize
13
+ @charset = LOWERCASE_CHARS + UPPERCASE_CHARS + DIGITS + SPECIAL_CHARS
14
+ @char_length = 8
15
+ @requirements = nil
16
+ end
17
+
18
+ def get_byte
19
+ dev_random = File.new("/dev/random", 'r')
20
+ dev_random.read(1).ord
21
+ end
22
+
23
+ def set_options(options={
24
+ 'lowercase' => true,
25
+ 'uppercase' => true,
26
+ 'digits' => true,
27
+ 'special' => true,
28
+ 'include' => nil,
29
+ 'exclude' => nil,
30
+ 'length' => 8,
31
+ 'requirements' => nil})
32
+
33
+ new_set = ""
34
+
35
+ if options['lowercase']
36
+ new_set += LOWERCASE_CHARS
37
+ end
38
+
39
+ if options['uppercase']
40
+ new_set += UPPERCASE_CHARS
41
+ end
42
+
43
+ if options['digits']
44
+ new_set += DIGITS
45
+ end
46
+
47
+ if options['special']
48
+ new_set += SPECIAL_CHARS
49
+ end
50
+
51
+ if options['include']
52
+ if options['include'].respond_to? :each
53
+ options['include'].each do |char|
54
+ unless new_set.includes? char
55
+ new_set += char
56
+ end
57
+ end
58
+ elsif options['include'].respond_to? :split
59
+ options['include'].split("").each do |char|
60
+ unless new_set.includes? char
61
+ new_set += char
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ if options['exclude']
68
+ if options['exclude'].respond_to? :each
69
+ options['exclude'].each do |char|
70
+ if new_set.includes? char
71
+ new_set -= char
72
+ end
73
+ end
74
+ elsif options['exclude'].respond_to? :split
75
+ options['exclude'].split("").each do |char|
76
+ if new_set.includes? char
77
+ new_set -= char
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ @charset = new_set
84
+
85
+ if options['length']
86
+ if options['length'].respond_to? :to_i
87
+ @char_length = options['length'].to_i
88
+ end
89
+ end
90
+
91
+ if options['requirements']
92
+ @requirements = options['requirements']
93
+ end
94
+
95
+ end
96
+
97
+ def requirements_met?(password)
98
+
99
+ if @requirements['uppercase']
100
+ if (password.split("") & UPPERCASE_CHARS.split("")).empty?
101
+ return false
102
+ end
103
+ end
104
+
105
+ if @requirements['lowercase']
106
+ if (password.split("") & LOWERCASE_CHARS.split("")).empty?
107
+ return false
108
+ end
109
+ end
110
+
111
+ if @requirements['digits']
112
+ if (password.split("") & DIGITS.split("")).empty?
113
+ return false
114
+ end
115
+ end
116
+
117
+ if @requirements['special']
118
+ if (password.split("") & SPECIAL_CHARS.split("")).empty?
119
+ return false
120
+ end
121
+ end
122
+
123
+ return true
124
+
125
+ end
126
+
127
+ def generate
128
+ new_password = ""
129
+
130
+ @char_length.times do
131
+ rand_num = get_byte
132
+ while rand_num >= @charset.length
133
+ rand_num -= @charset.length
134
+ end
135
+ new_password += @charset[rand_num]
136
+ end
137
+
138
+ if requirements_met? new_password
139
+ return new_password
140
+ else
141
+ return generate
142
+ end
143
+
144
+ end
145
+
146
+ end
147
+ end
@@ -0,0 +1,3 @@
1
+ module DevRandomPasswords
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dev-random-passwords
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Joel Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: On Linux, Unix or OSX /dev/random can be used to create really secure
42
+ passwords from random bytes. This gem provides an implementation to do just that.
43
+ email:
44
+ - joel@trosic.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".DS_Store"
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - dev-random-passwords.gemspec
56
+ - lib/.DS_Store
57
+ - lib/dev-random-passwords.rb
58
+ - lib/dev-random-passwords/version.rb
59
+ homepage: https://github.com/jbsmith86/dev-random-passwords
60
+ licenses:
61
+ - BSD-3-Clause-Clear
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Passwords that need to be used long term and are randomly generated need
83
+ more randomness than your standard random library
84
+ test_files: []