pass 0.0.5 → 0.0.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4c0d21c2d761abefac101b65714ce241d2a8450d
4
- data.tar.gz: ae1a4f552e22f3786e8dde74dc4481eda7710163
2
+ SHA256:
3
+ metadata.gz: 12c7cafaf8a91ed0368e4614da00d55b6523851122a14330daf44a5fbcf7637c
4
+ data.tar.gz: 3e591a5f56b686d273aafbadf40da32e3a70a0a16f9f97e832db5a6347896a92
5
5
  SHA512:
6
- metadata.gz: 5bff40017f7c2f257877f6b8ad3475cc3f26298c3d5a28d5925fa8887222c2427ace2e090cf7dabeba1291fc053eb9d4ad343747fc3b31179c02f504f2d2f2b3
7
- data.tar.gz: 241aeafbeeefe989c0d2894f051387bcba20f45bc8ca545cb9df833c29339ade99e084a91d027112521eccdc60dbec409826efd751a8d8766f6421bf31cd1ac2
6
+ metadata.gz: 17be1cb82ca32d01d359d11fd14bde4b93a4f6efe956396415c12e54c06a0fbed66b2978047db3ddc8ffe3b4ea9a6710020609483d19336ac627abc531dd45fc
7
+ data.tar.gz: ee878a0713c20dfcdc3a349f2951df271503bb86174b7024d38490b9ff10393cd8be58a4c5124e4c42e32459883e8489f17542f1bab30193841fd451e5b8f774
@@ -0,0 +1,36 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: CI
9
+
10
+ on:
11
+ push:
12
+ branches: [ main ]
13
+ pull_request:
14
+ branches: [ main ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+ runs-on: ubuntu-latest
22
+ strategy:
23
+ matrix:
24
+ ruby-version: [ '2.5', '2.6', '2.7', '3.0', '3.1' ]
25
+ steps:
26
+ - uses: actions/checkout@v3
27
+ - name: Set up Ruby
28
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
29
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
30
+ # uses: ruby/setup-ruby@v1
31
+ uses: ruby/setup-ruby@2b019609e2b0f1ea1a2bc8ca11cb82ab46ada124
32
+ with:
33
+ ruby-version: ${{ matrix.ruby-version }}
34
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
35
+ - name: Run tests for ${{ matrix.ruby }}
36
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .DS_Store
11
+ /.idea/
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in pass.gemspec
4
4
  gemspec
5
+
6
+ ruby '>= 2.5'
7
+
8
+ group :development do
9
+ gem 'rubocop', '~> 1.16.0'
10
+ end
data/README.md CHANGED
@@ -1,45 +1,65 @@
1
- # Pass
1
+ # pass
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/pass.svg)](https://badge.fury.io/rb/pass)
4
- [![Build Status](https://travis-ci.org/krhitoshi/pass.svg?branch=master)](https://travis-ci.org/krhitoshi/pass)
4
+ ![Testing workflow](https://github.com/krhitoshi/pass/workflows/Testing%20workflow/badge.svg)
5
5
 
6
6
  ## Description
7
7
 
8
- Pass is a command-line tool to generate random passwords.
8
+ The 'pass' command generates random passwords.
9
9
 
10
10
  ## Installation
11
11
 
12
- The first step is to install the gem
12
+ All you have to do is to install the gem
13
13
 
14
14
  ```
15
- gem install pass
15
+ $ gem install pass
16
16
  ```
17
17
 
18
18
  ## Usage
19
19
 
20
- You can run Pass to generate one random password. A generated password has 12 characters with more than one upper case letter, lower case letter, and numeric character.
20
+ You can run 'pass' to generate one random password.
21
+ Generated passwords have 20 characters and does not include ambiguous characters ``l o I O 1 " ' ` |``.
22
+ As default, a password consists of upper case letters, lower case letters, and numbers.
21
23
 
22
24
  ```
23
- pass
25
+ $ pass
24
26
  ```
25
27
 
26
28
  If you need more passwords, you can specify the number of passwords.
27
29
 
28
30
  ```
29
- pass 12
31
+ $ pass 12
30
32
  ```
31
33
 
32
- You can specify the password length by -c option.
34
+ You can specify the password length with -l or --length option.
33
35
 
34
36
  ```
35
- pass -c 18
37
+ $ pass -l 30
38
+ $ pass --length 50
39
+ ```
40
+
41
+ You can use -s or --symbols option to include symbols in passwords.
42
+
43
+ ```
44
+ $ pass -s
45
+ $ pass --symbols
46
+ ```
47
+
48
+ You can specify certain characters you don't want to put in passwords with -e or --exclude option.
49
+
50
+ ```
51
+ $ pass -e 'ABCD678'
52
+ $ pass --symbols --exclude '*[]{}/\'
36
53
  ```
37
54
 
38
55
  ## Options
39
56
 
40
57
  ```
41
- -c NUM specify password length
42
- -v, --version show version
58
+ -c [NUMBER] (deprecated) specify password length
59
+ -l, --length [NUMBER] specify password length
60
+ -s, --symbols include symbols
61
+ -e, --exclude [CHARACTERS] exclude characters
62
+ -v, --version show version
43
63
  ```
44
64
 
45
65
  ## License
data/exe/pass CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
5
5
  require 'rubygems'
6
- require 'pass'
6
+ require 'pass/cli'
7
7
 
8
- Pass.new.exec(ARGV)
8
+ Pass::CLI.new.exec(ARGV)
data/lib/pass/cli.rb ADDED
@@ -0,0 +1,77 @@
1
+ require 'optparse'
2
+ require 'pass'
3
+ require 'pass/version'
4
+
5
+ class Pass
6
+ class CLI
7
+ class Error < StandardError; end
8
+
9
+ def exec(argv)
10
+ options = {}
11
+ options[:length] = Pass::DEFAULT_PASSWORD_LENGTH
12
+
13
+ opts = OptionParser.new
14
+
15
+ opts.on('-c [NUMBER]', '(deprecated) specify password length') do |value|
16
+ options[:length] = option_to_i(value)
17
+ end
18
+
19
+ opts.on('-l', '--length [NUMBER]', 'specify password length') do |value|
20
+ options[:length] = option_to_i(value)
21
+ end
22
+
23
+ opts.on('-s', '--symbols', 'include symbols') do |value|
24
+ options[:symbols] = value
25
+ end
26
+
27
+ opts.on('-e', '--exclude [CHARACTERS]', 'exclude characters') do |value|
28
+ options[:exclude] = value
29
+ end
30
+
31
+ opts.on_tail('-v', '--version', 'show version') do
32
+ puts "pass #{Pass::VERSION}"
33
+ exit 0
34
+ end
35
+
36
+ opts.banner = banner
37
+
38
+ begin
39
+ res_argv = opts.parse!(argv)
40
+ num_passwords = if res_argv[0]
41
+ option_to_i(res_argv[0])
42
+ else
43
+ Pass::DEFAULT_NUM_PASSWORDS
44
+ end
45
+
46
+ pass = Pass.new(**options)
47
+
48
+ num_passwords.times do
49
+ puts pass.generate
50
+ end
51
+ rescue Pass::Error, Pass::CLI::Error, OptionParser::ParseError => e
52
+ abort "Error: #{e.message}"
53
+ end
54
+
55
+ exit 0
56
+ end
57
+
58
+ private
59
+
60
+ def option_to_i(opt)
61
+ Integer(opt)
62
+ rescue ArgumentError => _e
63
+ raise Error, "the option must be an integer: '#{opt}'"
64
+ end
65
+
66
+ def banner
67
+ <<~BANNER
68
+ Usage: pass [options] [number of passwords]
69
+
70
+ Description:
71
+ The 'pass' command generates random passwords.
72
+
73
+ Options:
74
+ BANNER
75
+ end
76
+ end
77
+ end
data/lib/pass/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Pass
2
- VERSION = "0.0.5"
2
+ VERSION = '0.0.6'
3
3
  end
data/lib/pass.rb CHANGED
@@ -1,109 +1,72 @@
1
- require 'optparse'
2
- require 'pass/version'
3
-
4
1
  class Pass
5
- MIN_NUM_CHARACTERS = 3
6
- NUM_CHARACTERS = 12
2
+ MIN_PASSWORD_LENGTH = 5
3
+ DEFAULT_NUM_PASSWORDS = 1
4
+ DEFAULT_PASSWORD_LENGTH = 20
7
5
 
8
- class Error < StandardError; end
6
+ ALPHABETIC_CHARS = ('a'..'z').to_a + ('A'..'Z').to_a
7
+ NUMERIC_CHARS = ('1'..'9').to_a
8
+ SYMBOL_CHARS = ('!'..'/').to_a + (':'..'@').to_a + ('['..'`').to_a + ('{'..'~').to_a
9
+ AMBIGUOUS_CHARS = %w[l o I O 1 " ' ` |]
9
10
 
10
- def initialize
11
- @list_carachters = ('a'..'z').to_a + ('A'..'Z').to_a + ('1'..'9').to_a - %w[l o I O 1]
12
- @num_iteration = 100
11
+ class Error < StandardError; end
13
12
 
14
- # Password must include digit, upper case, and lower case.
15
- @validation_regexps = [/\d/, /[a-z]/, /[A-Z]/]
13
+ def initialize(**options)
14
+ @options = { length: DEFAULT_PASSWORD_LENGTH }
15
+ @options.update(options)
16
16
  end
17
17
 
18
- def generate(num = NUM_CHARACTERS)
19
- if !integer?(num) || num < MIN_NUM_CHARACTERS
20
- raise Pass::Error, "Invalid Argument: number of characters should be more than #{MIN_NUM_CHARACTERS}."
21
- end
18
+ def char_list
19
+ list = ALPHABETIC_CHARS + NUMERIC_CHARS
22
20
 
23
- @num_iteration.times do
24
- rest_num = num
25
- pass = ""
26
- while rest_num > list_size do
27
- pass += generate_password(list_size)
28
- rest_num -= list_size
29
- end
30
- pass += generate_password(rest_num)
31
- return pass if valid?(pass)
32
- end
33
- raise Pass::Error, "Not Converged: #{@num_iteration} times"
34
- end
21
+ list += SYMBOL_CHARS if @options[:symbols]
35
22
 
36
- def valid?(pass)
37
- @validation_regexps.all?{|reg| reg =~ pass}
38
- end
23
+ list -= exclude_char_list
39
24
 
40
- def multi_generate(num_password, num_character = NUM_CHARACTERS)
41
- passwords = []
42
- num_password.times do
43
- passwords << generate(num_character)
44
- end
45
- passwords
25
+ list
46
26
  end
47
27
 
48
- def Pass.generate(num = NUM_CHARACTERS)
49
- Pass.new.generate(num)
28
+ def exclude_char_list
29
+ list = AMBIGUOUS_CHARS
30
+ list += @options[:exclude].split(//).sort.uniq if @options[:exclude]
31
+ list
50
32
  end
51
33
 
52
- def exec(argv)
53
- num_characters = NUM_CHARACTERS
54
- opts = OptionParser.new
55
- opts.on('-c NUM', 'specify password length') do |value|
56
- num_characters = value
57
- end
58
- opts.on_tail('-v', '--version', 'show version') do
59
- puts "#{self.class.name} #{version}"
60
- exit 0
61
- end
62
- opts.banner = <<END
63
- Usage: pass [options] [number of passwords]
64
-
65
- Description:
66
- Generates random passwords.
67
-
68
- Options:
69
- END
70
- begin
71
- res_argv = opts.parse!(argv)
72
- num_times = res_argv[0] || 1
73
- puts multi_generate(num_times.to_i, num_characters.to_i)
74
- rescue SystemExit
75
- rescue Exception => e
76
- $stderr.puts "Error: #{e.message}"
77
- exit 1
34
+ def generate
35
+ length = @options[:length]
36
+
37
+ if length < MIN_PASSWORD_LENGTH
38
+ raise Pass::Error,
39
+ "Invalid Argument: password length must be more than #{MIN_PASSWORD_LENGTH}."
78
40
  end
79
- exit 0
80
- end
81
41
 
82
- def num_iteration
83
- @num_iteration
84
- end
42
+ rest_length = length
43
+ result = ""
44
+ # append append password string until 'result' reaches the 'length'
45
+ while rest_length > char_list_size
46
+ result += generate_password_base(char_list_size)
47
+ rest_length -= char_list_size
48
+ end
49
+ result += generate_password_base(rest_length)
85
50
 
86
- def num_iteration=(value)
87
- raise(Error, "Invalid Argument: num_iteration #{value}") if !integer?(value) || value <= 0
88
- @num_iteration = value
51
+ result
89
52
  end
90
53
 
91
- def version
92
- VERSION
54
+ def self.generate(num = DEFAULT_PASSWORD_LENGTH)
55
+ new(length: num).generate
93
56
  end
94
57
 
95
58
  private
96
- def integer?(value)
97
- value.kind_of?(Integer)
98
- end
99
59
 
100
- def list_size
101
- @list_carachters.size
60
+ def char_list_size
61
+ char_list.size
102
62
  end
103
63
 
104
- def generate_password(num)
105
- raise ArgumentError, "argument must be less than #{list_size}" if num > list_size
106
- @list_carachters.sample(num).join
107
- end
64
+ # generate a password that is long less than 'char_list_size'
65
+ def generate_password_base(length)
66
+ if length > char_list_size
67
+ raise ArgumentError, "argument must be less than #{char_list_size}"
68
+ end
108
69
 
70
+ char_list.sample(length).join
71
+ end
109
72
  end
data/pass.gemspec CHANGED
@@ -21,8 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.13"
25
- spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rake", "~> 12.0"
26
25
  spec.add_development_dependency "rspec", "~> 3.0"
27
26
  spec.add_development_dependency "pry"
28
27
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hitoshi Kurokawa
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-17 00:00:00.000000000 Z
11
+ date: 2022-05-18 00:00:00.000000000 Z
12
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.13'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.13'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '10.0'
19
+ version: '12.0'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '10.0'
26
+ version: '12.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -74,9 +60,9 @@ executables:
74
60
  extensions: []
75
61
  extra_rdoc_files: []
76
62
  files:
63
+ - ".github/workflows/ci.yml"
77
64
  - ".gitignore"
78
65
  - ".rspec"
79
- - ".travis.yml"
80
66
  - Gemfile
81
67
  - LICENSE.txt
82
68
  - README.md
@@ -85,13 +71,14 @@ files:
85
71
  - bin/setup
86
72
  - exe/pass
87
73
  - lib/pass.rb
74
+ - lib/pass/cli.rb
88
75
  - lib/pass/version.rb
89
76
  - pass.gemspec
90
77
  homepage: http://github.com/krhitoshi/pass
91
78
  licenses:
92
79
  - MIT
93
80
  metadata: {}
94
- post_install_message:
81
+ post_install_message:
95
82
  rdoc_options: []
96
83
  require_paths:
97
84
  - lib
@@ -106,9 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
93
  - !ruby/object:Gem::Version
107
94
  version: '0'
108
95
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.5.1
111
- signing_key:
96
+ rubygems_version: 3.3.7
97
+ signing_key:
112
98
  specification_version: 4
113
99
  summary: Password Generator (CLI)
114
100
  test_files: []
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.0.0-p648
5
- - 2.1.10
6
- - 2.2.5
7
- - 2.3.1
8
- before_install: gem install bundler -v 1.13.5