pwgen 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +30 -0
- data/.travis.yml +37 -0
- data/CHANGELOG.md +5 -0
- data/CODEOWNERS +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/pwgen +76 -0
- data/lib/pwgen.rb +137 -0
- data/lib/pwgen/version.rb +3 -0
- data/pwgen.gemspec +35 -0
- metadata +187 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 781a8343812268d938ed4c403ad1d00bef54f6cfa59ce8563fd66e264b917319
|
4
|
+
data.tar.gz: 9e2afc567d6ce15332836f8e21ae9008f6c8ceeb4cd094fe1b47f1f94bdec728
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 14bbf8f04c8fe2df6240d6b00996066dc4f4f7eb408bc2471f006a18624318990c3ac60738b29b54d40dacd68b711e469d5baac6a2a0de70ebc0b9093aad1c13
|
7
|
+
data.tar.gz: 6b8899bbfc35f3bc63c02612033cde3ff95ca095cc43df15c325358535dd101ca792c178b92e06089d8ac078a5a76eb77bedadae79170fd6f279abd6e6a86620
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Layout/IndentationWidth:
|
2
|
+
Width: 4
|
3
|
+
|
4
|
+
Metrics/AbcSize:
|
5
|
+
Max: 50
|
6
|
+
|
7
|
+
Metrics/LineLength:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/BlockLength:
|
11
|
+
Max: 40
|
12
|
+
|
13
|
+
Metrics/CyclomaticComplexity:
|
14
|
+
Max: 20
|
15
|
+
|
16
|
+
Metrics/MethodLength:
|
17
|
+
Max: 60
|
18
|
+
|
19
|
+
Metrics/PerceivedComplexity:
|
20
|
+
Max: 20
|
21
|
+
|
22
|
+
Style/GlobalVars:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/RaiseArgs:
|
26
|
+
EnforcedStyle: compact
|
27
|
+
|
28
|
+
Style/WordArray:
|
29
|
+
EnforcedStyle: brackets
|
30
|
+
|
data/.travis.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
sudo: required
|
2
|
+
matrix:
|
3
|
+
include:
|
4
|
+
- language: ruby
|
5
|
+
rvm: 2.2
|
6
|
+
before_install:
|
7
|
+
- gem install bundler -v 1.16.1
|
8
|
+
- language: ruby
|
9
|
+
rvm: 2.4.4
|
10
|
+
before_install:
|
11
|
+
- gem install bundler -v 1.17.3
|
12
|
+
- language: ruby
|
13
|
+
rvm: 2.4.4
|
14
|
+
before_install:
|
15
|
+
- gem install bundler -v 2.0.1
|
16
|
+
- language: ruby
|
17
|
+
env: SKIP_INTERPRETER=true
|
18
|
+
rvm: 2.4.4
|
19
|
+
before_install:
|
20
|
+
- git clone https://github.com/TravisToolbox/rubocop-travis.git
|
21
|
+
install:
|
22
|
+
- ./rubocop-travis/install.sh
|
23
|
+
script:
|
24
|
+
- ./rubocop-travis/scan.sh
|
25
|
+
- language: ruby
|
26
|
+
rvm: 2.2
|
27
|
+
before_install:
|
28
|
+
- mkdir travis
|
29
|
+
- git clone https://github.com/TravisToolbox/awesomebot-travis.git travis/awesomebot
|
30
|
+
install:
|
31
|
+
- ./travis/awesomebot/install.sh
|
32
|
+
script:
|
33
|
+
- ./travis/awesomebot/scan.sh
|
34
|
+
notifications:
|
35
|
+
email: false
|
36
|
+
slack:
|
37
|
+
secure: lcZauiSkJHhubO8rnsj+mbsL5GSRftPmcjb8Vz1ZQDXIr+exOnoOUjFmh66UoqdVPTSrfvX0MSrMocubzC+yoXA8cpGLZP+Bo01T5109VcsRLwoTPiFD6lrugB7VpIKm6OaD1pRzA5fDi76FU3MthAAVNb+z0//jXU8lm6sLg9Oxx/sMuOlecZiEvpqL+noB6wNPmhuRD/w1CJX7ThjCLZ4a9xfj1KXbYHaaJUJoxLRK0RLKUQ0CFYDUovImQVwft82Xb8EiDjnEyX/DkN/Vn6CmF7UFrGB6nB/0fZJ97bR5NyaIABAytQGBHHmHilqE/plbw9CPTcbkPDjaRaR7eZLwLzpNYpI1Dr7KM9Yog04Rjw2hwyJisrac4lkCk17tAw/FUUfkiutH6ff8khB6VZOV3iE1NxPqGwXTjypOMIYED7YcCA0KZC8+HIt9kFHNva6EsX4V3DWe9VNzoq+hZJKVHbUQj3hz+5FMC0MlpVQ83ACqM5UhPSz6QggnhxHFzAkQ1MFocSsh9kg7Rbmn5zCVa9VIL916EYk/9pkfDAYeITrnf8/giEgQoMo8fUOl+ugfdo19I0aQKs4TXkDW9TRxXPOeqaCisCCMbc1AXKF9bKtGeN6eMI+FaKpC/bW66rMTDxHw5jgSfKSEDkLKJc85c7i929aShS9DUadHPdc=
|
data/CHANGELOG.md
ADDED
data/CODEOWNERS
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at wolf@tgwolf.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Tim Gurney aka Wolf
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
[![Build Status](https://img.shields.io/travis/AntiPhotonltd/password_generator/master.svg)](https://travis-ci.org/AntiPhotonltd/password_generator)
|
2
|
+
[![Software License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md)
|
3
|
+
[![Release](https://img.shields.io/github/release/AntiPhotonltd/password_generator.svg)](https://github.com/AntiPhotonltd/password_generator/releases/latest)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/password_generator.svg)](https://badge.fury.io/rb/password_generator)
|
5
|
+
[![Github commits (since latest release)](https://img.shields.io/github/commits-since/AntiPhotonltd/password_generator/latest.svg)](https://github.com/AntiPhotonltd/password_generator/commits)
|
6
|
+
[![GitHub repo size in bytes](https://img.shields.io/github/repo-size/AntiPhotonltd/password_generator.svg)](https://github.com/AntiPhotonltd/password_generator)
|
7
|
+
[![GitHub contributors](https://img.shields.io/github/contributors/AntiPhotonltd/password_generator.svg)](https://github.com/AntiPhotonltd/password_generator)
|
8
|
+
|
9
|
+
# Pwgen
|
10
|
+
|
11
|
+
A full featured ruby gem for password creation.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'pwgen'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install pwgen
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Basic password generation
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'pwgen'
|
35
|
+
|
36
|
+
Pwgen::Password.generate_password(length)
|
37
|
+
puts Pwgen::Password.password
|
38
|
+
puts Pwgen::Password.phonetic_password
|
39
|
+
```
|
40
|
+
|
41
|
+
There are a number of options that can be password:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Pwgen::Password.configure(options)
|
45
|
+
```
|
46
|
+
|
47
|
+
* :skip_lower_case [true | false] (Default: false) - No lower case letters in password.
|
48
|
+
* :skip_upper_case [true | false] (Default: false) - No upper case letters in password.
|
49
|
+
* :skip_digits [true | false] (Default: false) - No digits in password.
|
50
|
+
* :skip_symbols [true | false] (Default: false) - No symbols in password.
|
51
|
+
* :dont_exclude_unfrieldly_chars [true | false] (Default: false) - Remove 'unfriendly characters' ($ S s 5 B b 8 | I i o 0 1 l O !)
|
52
|
+
* :skip_url_unsafe [true | false] (Default: false) - Remove URL unsafe characters ($ & + , / : ; = ? @ < > # % { } | ^ ~ [ ] \ " `)
|
53
|
+
* :digits <number> - Force a specific minimum number of digits in the password.
|
54
|
+
* :symbols <number> - Force a specific minimum number of symbols in the password.
|
55
|
+
* :skip_phonetic [true | false] (Default: false) - Skip the creation of the phonetic password.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
Pwgen::Password.configure(:skip_lower_case => true, :digits => 4)
|
59
|
+
```
|
60
|
+
|
61
|
+
You can also pass the options parameter to the 'generate_password' method to override the settings for a specific password creation.
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
66
|
+
|
67
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
68
|
+
|
69
|
+
## Testing
|
70
|
+
|
71
|
+
For local testing make sure that you run `bundle exec rspec spec` and then `rake install` to install the gem locally.
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pwgen. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
80
|
+
|
81
|
+
## Code of Conduct
|
82
|
+
|
83
|
+
Everyone interacting in the Pwgen project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/pwgen/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pwgen"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/pwgen
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require "pwgen"
|
5
|
+
|
6
|
+
# -------------------------------------------------------------------------------- #
|
7
|
+
# Generate Password #
|
8
|
+
# -------------------------------------------------------------------------------- #
|
9
|
+
# Generate the password. #
|
10
|
+
# -------------------------------------------------------------------------------- #
|
11
|
+
|
12
|
+
def generate_password(options)
|
13
|
+
Pwgen::Password.generate_password(options[:length])
|
14
|
+
|
15
|
+
pputs Pwgen::Password.password
|
16
|
+
|
17
|
+
pputs Pwgen::Password.phonetic_password if options[:phonetic]
|
18
|
+
end
|
19
|
+
|
20
|
+
# -------------------------------------------------------------------------------- #
|
21
|
+
# Process Arguments #
|
22
|
+
# -------------------------------------------------------------------------------- #
|
23
|
+
# This function will process the input from the command line and work out what it #
|
24
|
+
# is that the user wants to see. #
|
25
|
+
# #
|
26
|
+
# This is the main processing function where all the processing logic is handled. #
|
27
|
+
# -------------------------------------------------------------------------------- #
|
28
|
+
|
29
|
+
def process_arguments
|
30
|
+
options = {}
|
31
|
+
# Enforce the presence of
|
32
|
+
mandatory = %I[length]
|
33
|
+
|
34
|
+
optparse = OptionParser.new do |opts|
|
35
|
+
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)}"
|
36
|
+
|
37
|
+
opts.on('-h', '--help', 'Display this screen') do
|
38
|
+
puts opts
|
39
|
+
exit(1)
|
40
|
+
end
|
41
|
+
opts.on('-l', '--length string', 'The length of the password') do |length|
|
42
|
+
options[:length] = length
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
begin
|
47
|
+
optparse.parse!
|
48
|
+
missing = mandatory.select { |param| options[param].nil? }
|
49
|
+
raise OptionParser::MissingArgument.new(missing.join(', ')) unless missing.empty?
|
50
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
|
51
|
+
puts e.to_s
|
52
|
+
puts optparse
|
53
|
+
exit(1)
|
54
|
+
end
|
55
|
+
|
56
|
+
generate_password(options)
|
57
|
+
end
|
58
|
+
|
59
|
+
# -------------------------------------------------------------------------------- #
|
60
|
+
# Main() #
|
61
|
+
# -------------------------------------------------------------------------------- #
|
62
|
+
# The main function where all of the heavy lifting and script config is done. #
|
63
|
+
# -------------------------------------------------------------------------------- #
|
64
|
+
|
65
|
+
def main
|
66
|
+
process_arguments
|
67
|
+
end
|
68
|
+
|
69
|
+
main
|
70
|
+
|
71
|
+
# -------------------------------------------------------------------------------- #
|
72
|
+
# End of Script #
|
73
|
+
# -------------------------------------------------------------------------------- #
|
74
|
+
# This is the end - nothing more to see here. #
|
75
|
+
# -------------------------------------------------------------------------------- #
|
76
|
+
|
data/lib/pwgen.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'pwgen/version'
|
2
|
+
|
3
|
+
require 'phonetic_encoder'
|
4
|
+
require 'punctuation_name'
|
5
|
+
require 'to_words'
|
6
|
+
|
7
|
+
#
|
8
|
+
# Docs to go here
|
9
|
+
#
|
10
|
+
module Pwgen
|
11
|
+
#
|
12
|
+
# docs to go here
|
13
|
+
#
|
14
|
+
class Password
|
15
|
+
UNFRIENDLY_CHARS = ['$', 'S', 's', '5', 'B', 'b', '8', '|', 'I', 'i', 'o', '0', '1', 'l', 'O', '!'].freeze
|
16
|
+
URL_UNSAFE = ['$', '&', '+', ',', '/', ':', ';', '=', '?', '@', '<', '>', '#', '%', '{', '}', '|', '^', '~', '[', ']', '\\', '"', '`'].freeze
|
17
|
+
|
18
|
+
$lower_case = []
|
19
|
+
$upper_case = []
|
20
|
+
$digits = []
|
21
|
+
$symbols = []
|
22
|
+
$alpha = []
|
23
|
+
$alphanum = []
|
24
|
+
$full_character_set = []
|
25
|
+
|
26
|
+
$password = ''
|
27
|
+
$phonetic_password = ''
|
28
|
+
|
29
|
+
def self.password
|
30
|
+
$password
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.phonetic_password
|
34
|
+
$phonetic_password
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.reset(options = nil)
|
38
|
+
$password = ''
|
39
|
+
$phonetic_password = ''
|
40
|
+
|
41
|
+
configure(options) unless options.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.configure(options)
|
45
|
+
$lower_case = []
|
46
|
+
$lower_case = ('a'..'z').to_a unless options[:skip_lower_case]
|
47
|
+
$lower_case -= UNFRIENDLY_CHARS unless options[:dont_exclude_unfrieldly_chars]
|
48
|
+
|
49
|
+
$upper_case = []
|
50
|
+
$upper_case = ('A'..'Z').to_a unless options[:skip_upper_case]
|
51
|
+
$upper_case -= UNFRIENDLY_CHARS unless options[:dont_exclude_unfrieldly_chars]
|
52
|
+
|
53
|
+
$digits = []
|
54
|
+
$digits = ('0'..'9').to_a unless options[:skip_digits]
|
55
|
+
$digits -= UNFRIENDLY_CHARS unless options[:dont_exclude_unfrieldly_chars]
|
56
|
+
|
57
|
+
$symbols = []
|
58
|
+
$symbols = ['!', '@', '#', '£', '$', '%', '^', '&', '*', '(', ')', '-', '_', '+', '=', '{', '}', '[', ']', ':', ';', '"', '\'', '|', '\\', '~', '`', '<', '>', '?', ',', '.', '/', '\ '].freeze unless options[:skip_symbols]
|
59
|
+
$symbols -= UNFRIENDLY_CHARS unless options[:dont_exclude_unfrieldly_chars]
|
60
|
+
$symbols -= URL_UNSAFE if options[:skip_url_unsafe]
|
61
|
+
|
62
|
+
$alpha = []
|
63
|
+
$alpha = $lower_case + $upper_case
|
64
|
+
|
65
|
+
$alphanum = []
|
66
|
+
$alphanum = $lower_case + $upper_case + $digits
|
67
|
+
|
68
|
+
$full_character_set = []
|
69
|
+
$full_character_set = $alphanum + $symbols
|
70
|
+
|
71
|
+
raise 'You messed up!' if $full_character_set.empty?
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.show_configuration
|
75
|
+
puts "Lower case: #{$lower_case}"
|
76
|
+
puts "Upper case: #{$upper_case}"
|
77
|
+
puts "Digits: #{$digits}"
|
78
|
+
puts "Symbols: #{$symbols}"
|
79
|
+
|
80
|
+
puts "Alpha: #{$alpha}"
|
81
|
+
puts "AlphaNumeric: #{$alphanum}"
|
82
|
+
|
83
|
+
puts "Unfriendly Chars: #{UNFRIENDLY_CHARS}"
|
84
|
+
puts "URL Unsafe: #{URL_UNSAFE}"
|
85
|
+
|
86
|
+
puts "Full Character Set: #{$full_character_set}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.generate_password(length = 12, options = {})
|
90
|
+
raise 'length must be an integer!' unless length.is_a? Integer
|
91
|
+
raise 'length must be a positive integer!' unless length > 0
|
92
|
+
|
93
|
+
reset(options)
|
94
|
+
|
95
|
+
shuffle = false
|
96
|
+
|
97
|
+
if options[:digits]
|
98
|
+
digits = options[:digits].to_i
|
99
|
+
|
100
|
+
$password += (1..digits).collect { $digits[rand($digits.size)] }.join
|
101
|
+
length -= digits
|
102
|
+
shuffle = true
|
103
|
+
end
|
104
|
+
|
105
|
+
if options[:symbols]
|
106
|
+
symbols = options[:symbols].to_i
|
107
|
+
|
108
|
+
$password += (1..symbols).collect { $symbols[rand($symbols.size)] }.join
|
109
|
+
length -= symbols
|
110
|
+
shuffle = true
|
111
|
+
end
|
112
|
+
|
113
|
+
$password += (1..length).collect { $full_character_set[rand($full_character_set.size)] }.join
|
114
|
+
$password = $password.split('').shuffle.join if shuffle
|
115
|
+
|
116
|
+
$phonetic_password = calculate_phonetic_password($password) unless options[:skip_phonetic]
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.calculate_phonetic_password(password)
|
120
|
+
phonetic = ''
|
121
|
+
|
122
|
+
password.split('').each do |letter|
|
123
|
+
phonetic << if letter =~ /[[:digit:]]/
|
124
|
+
letter.to_i.to_words
|
125
|
+
elsif letter =~ /[[:upper:]]/
|
126
|
+
letter.to_s.phonetic_encode.upcase
|
127
|
+
elsif letter =~ /[[:lower:]]/
|
128
|
+
letter.to_s.phonetic_encode.downcase
|
129
|
+
else
|
130
|
+
format('(%<name>s)', name: letter.to_s.punctuation_name)
|
131
|
+
end
|
132
|
+
phonetic << ' '
|
133
|
+
end
|
134
|
+
phonetic.rstrip
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
data/pwgen.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "pwgen/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pwgen"
|
8
|
+
spec.version = Pwgen::VERSION
|
9
|
+
spec.authors = ["Tim Gurney aka Wolf"]
|
10
|
+
spec.email = ["wolf@tgwolf.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A full featured ruby gem for password creation.}
|
13
|
+
spec.description = %q{A full featured ruby gem for password creation.}
|
14
|
+
spec.homepage = "https://github.com/AntiPhotonltd/password_generator"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
|
28
|
+
spec.add_development_dependency 'phonetic_encoder', '~> 1.1'
|
29
|
+
spec.add_development_dependency 'punctuation_name', '~> 1.1'
|
30
|
+
spec.add_development_dependency 'to_words', '~> 1.1'
|
31
|
+
|
32
|
+
spec.add_runtime_dependency 'phonetic_encoder', '~> 1.1.1'
|
33
|
+
spec.add_runtime_dependency 'punctuation_name', '~> 1.1.1'
|
34
|
+
spec.add_runtime_dependency 'to_words', '~> 1.1.1'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pwgen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Gurney aka Wolf
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-28 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: phonetic_encoder
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: punctuation_name
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: to_words
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: phonetic_encoder
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.1.1
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.1.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: punctuation_name
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.1.1
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.1.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: to_words
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.1.1
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.1.1
|
139
|
+
description: A full featured ruby gem for password creation.
|
140
|
+
email:
|
141
|
+
- wolf@tgwolf.com
|
142
|
+
executables:
|
143
|
+
- pwgen
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- ".gitignore"
|
148
|
+
- ".rspec"
|
149
|
+
- ".rubocop.yml"
|
150
|
+
- ".travis.yml"
|
151
|
+
- CHANGELOG.md
|
152
|
+
- CODEOWNERS
|
153
|
+
- CODE_OF_CONDUCT.md
|
154
|
+
- Gemfile
|
155
|
+
- LICENSE.txt
|
156
|
+
- README.md
|
157
|
+
- Rakefile
|
158
|
+
- bin/console
|
159
|
+
- bin/setup
|
160
|
+
- exe/pwgen
|
161
|
+
- lib/pwgen.rb
|
162
|
+
- lib/pwgen/version.rb
|
163
|
+
- pwgen.gemspec
|
164
|
+
homepage: https://github.com/AntiPhotonltd/password_generator
|
165
|
+
licenses:
|
166
|
+
- MIT
|
167
|
+
metadata: {}
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
requirements: []
|
183
|
+
rubygems_version: 3.0.2
|
184
|
+
signing_key:
|
185
|
+
specification_version: 4
|
186
|
+
summary: A full featured ruby gem for password creation.
|
187
|
+
test_files: []
|