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 +5 -5
- data/.github/workflows/ci.yml +36 -0
- data/.gitignore +1 -0
- data/Gemfile +6 -0
- data/README.md +32 -12
- data/exe/pass +2 -2
- data/lib/pass/cli.rb +77 -0
- data/lib/pass/version.rb +1 -1
- data/lib/pass.rb +46 -83
- data/pass.gemspec +1 -2
- metadata +10 -24
- data/.travis.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 12c7cafaf8a91ed0368e4614da00d55b6523851122a14330daf44a5fbcf7637c
|
4
|
+
data.tar.gz: 3e591a5f56b686d273aafbadf40da32e3a70a0a16f9f97e832db5a6347896a92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,45 +1,65 @@
|
|
1
|
-
#
|
1
|
+
# pass
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/pass)
|
4
|
-
|
4
|
+

|
5
5
|
|
6
6
|
## Description
|
7
7
|
|
8
|
-
|
8
|
+
The 'pass' command generates random passwords.
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
12
|
-
|
12
|
+
All you have to do is to install the gem
|
13
13
|
|
14
14
|
```
|
15
|
-
|
15
|
+
$ gem install pass
|
16
16
|
```
|
17
17
|
|
18
18
|
## Usage
|
19
19
|
|
20
|
-
You can run
|
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
|
-
|
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
|
-
|
31
|
+
$ pass 12
|
30
32
|
```
|
31
33
|
|
32
|
-
You can specify the password length
|
34
|
+
You can specify the password length with -l or --length option.
|
33
35
|
|
34
36
|
```
|
35
|
-
|
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
|
-
|
42
|
-
|
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
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
data/lib/pass.rb
CHANGED
@@ -1,109 +1,72 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'pass/version'
|
3
|
-
|
4
1
|
class Pass
|
5
|
-
|
6
|
-
|
2
|
+
MIN_PASSWORD_LENGTH = 5
|
3
|
+
DEFAULT_NUM_PASSWORDS = 1
|
4
|
+
DEFAULT_PASSWORD_LENGTH = 20
|
7
5
|
|
8
|
-
|
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
|
-
|
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
|
-
|
15
|
-
@
|
13
|
+
def initialize(**options)
|
14
|
+
@options = { length: DEFAULT_PASSWORD_LENGTH }
|
15
|
+
@options.update(options)
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
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
|
-
@
|
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
|
-
|
37
|
-
@validation_regexps.all?{|reg| reg =~ pass}
|
38
|
-
end
|
23
|
+
list -= exclude_char_list
|
39
24
|
|
40
|
-
|
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
|
49
|
-
|
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
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
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
|
92
|
-
|
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
|
101
|
-
|
60
|
+
def char_list_size
|
61
|
+
char_list.size
|
102
62
|
end
|
103
63
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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 "
|
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.
|
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:
|
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: '
|
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: '
|
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
|
-
|
110
|
-
|
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: []
|