randpass 0.2.0 → 0.3.0

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
2
  SHA256:
3
- metadata.gz: cbb8602dd6f07d03f70be18df83861597616e0f3c71608cafe2f4b5453857879
4
- data.tar.gz: 93948d8bebdf6d8fbcbb7e8c36ac196e2b4bc210cdade6016d624f90f45b024a
3
+ metadata.gz: ff3fc4f874b2494d17acd4781ead4b775d83f5498258e77ccea97bfeae90ab00
4
+ data.tar.gz: 015f7ae1c0567a0c403e31447c6f2f4ce63342128a9e9da6b41da95c3930ef22
5
5
  SHA512:
6
- metadata.gz: b08fa98c352f7de784e226ff7e3fbc6dff57ee6937113300386767e6557d407547591b971fb2492d58f3c6f68197c7acfc8a1a031dce99ff8d8e8c9469945d65
7
- data.tar.gz: f8b505b3194cab5340894203b38d0e7dd379445c714bb9049cb56d732bb8ba9e477a54a26be1024a841ee4cfb049122dcae9b74062a64d24f6ec9c1475ab6958
6
+ metadata.gz: 9a6e5995afa0b9eb6ffa5b0973587f925b2989a1beed08d7a2bd1681266288c18a06d146964f829fd5f9b6acdacb6768c2e47adacb5d15f1bbccb98c607d0d60
7
+ data.tar.gz: 8320a134f57d210ee2e47e87571dfa3937e903d9c8dd2c0225e017a2d89cbdd695bc07cf3c5440b5eadbc148c09a868bdb73a146f14322d08a0069306fd1ab49
data/README.md CHANGED
@@ -1,17 +1,10 @@
1
- ### UNDER DEVELOPMENT
2
-
3
- # Randpass
4
-
5
- V-0.2.0:
6
- - copy password in clipboard
7
- - add storage module
8
-
1
+ # Randpass v0.3.0
9
2
 
10
3
  Ruby random password generator.
11
- Generate password and copy in clipboard, or generate list and save as `.txt` file.
4
+ Generate password and copy in clipboard, or generate list and/or save it as `.txt` file.
12
5
  File is saved as plain text, it is up to end-user to decide how to secure it.
13
6
 
14
- Password is generated with `SecureRandom#base64` and a few special characters `! # * $ % _ @`
7
+ Password is generated with `SecureRandom#base64` and a few (random) special characters `! # * $ % _ @`
15
8
 
16
9
 
17
10
  ## Dependencies
@@ -24,25 +17,41 @@ Setup script will check and install `xsel` if nothing is found.
24
17
 
25
18
  Use from terminal:
26
19
 
20
+ When generating a single password, you don't need any argument, or you can add number of password characters (default is 25). By default, password is printed in STDOUT and copied to clipboard, but not saved as file.
21
+
27
22
  - generate password with 25 characters
28
23
  `randpass`
29
24
 
30
25
  - generate password with 30 characters
31
26
  `randpass 30`
27
+ `randpass --char 30`
32
28
 
33
29
  - clear clipboard
34
- `randpass -c`
30
+ `randpass -k`
31
+ `randpass --clear`
32
+
33
+ - add `-c` or `--noc` to disable clipboard copy
34
+ `randpass 35 -c`
35
+
36
+ - add `-p` or `--nop` to disable STDOUT
37
+ `randpass 20 -p`
38
+
39
+ When generating a list of passwords, you need to supply `-n` or `--char` to set number of password characters (default is 25). Passwords will be saved in a current working directory (unless otherwise specified) in format `randpass_#{Time.now.to_i}.txt`. This way we avoid overwrite, and it's possible to get time of file generation with `Time.at TIME_INTEGER`
35
40
 
36
41
  - generate password list from comments (20 characters long password)
37
- `randpass -n 20 -l password1 password2 password3`
42
+ `randpass -n 20 -l GitHub RubyGems AnotherWebSite`
38
43
 
39
44
  - generate password list with 10 passwords - without comments
40
45
  `randpass -r 10`
41
- `randpass -n 20 -r 10`
46
+ `randpass -n 20 -r 10`
47
+
48
+ - add `-s` or `--nos` to disable saving list as a file
49
+ `randpass -n 20 -r 5 -s`
50
+ `randpass -r 10 --nos --noc`
51
+
52
+ - add `-d` or `--dir` as location to store password list
53
+ `randpass -r 10 -d 'my_path/directory'`
42
54
 
43
- - add `--noc` and/or `--nop` to diasable copy and stdout, respectively
44
- `randpass 35 --noc`
45
- `randpass -r 10 --noc --nop`
46
55
 
47
56
 
48
57
  ## How to install
@@ -50,26 +59,25 @@ Setup script will check and install `xsel` if nothing is found.
50
59
  - install from rubygems
51
60
 
52
61
  ```
53
- gem install randpass && randpass -s
62
+ gem install randpass && randpass -i
54
63
  ```
55
64
  - download from github with ssh
56
65
 
57
66
  ```
58
67
  git clone git@github.com:alx3dev/randpass \
59
- cd randpass && bin/setup
68
+ cd randpass && randpass -i
60
69
  ```
61
70
  - download from github with https
62
71
 
63
72
  ```
64
73
  git clone https://www.github.com/alx3dev/randpass \
65
- cd randpass && bin/setup
66
- ```
67
-
68
- To build your own gem, run `rake bundle`, and install it locally with `gem install pkg/randpass-0.2.0.gem`
74
+ cd randpass && randpass -i
75
+ ```
69
76
 
70
77
 
71
78
  Tested on:
72
79
  - ruby `2.7.5`
73
80
  - ruby `3.0.3`
74
- - ruby `3.1.0-preview1`
81
+ - ruby `3.1.0`
82
+ - ruby `3.1.3`
75
83
  - jruby `9.3.2.0`
@@ -2,23 +2,28 @@ require_relative '../lib/randpass/version' unless defined? Randpass::VERSION
2
2
 
3
3
  require 'optimist'
4
4
 
5
+ # Check if password should be printed and/or copied
6
+ module Output
7
+ # @param [String] pass **Required**. Password
8
+ def self.[](txt)
9
+ txt = txt.join("\n") if txt.is_a?(Array)
10
+ STDOUT.puts(txt) unless Randpass.noprint?
11
+ Clipboard.copy(txt) unless Randpass.nocopy?
12
+ end
13
+ end
14
+
5
15
  BANNER =
6
16
  <<~DESC
7
17
  randpass
8
- >> generate 25 chars long password
9
-
10
18
  randpass 33
11
- >> generate 33 chars long password
12
-
13
- ----------------------------------------
19
+ randpass -n 25 -r 5 --dir 'output/directory'
20
+ :
14
21
  DESC
15
22
 
16
23
  SETUP_DESCRIPTION =
17
24
  <<~DESC
18
25
  Install gem dependencies
19
26
  xsel or xclip on linux (for clipboard manipulation)
20
-
21
- ----------------------------------------
22
27
  DESC
23
28
 
24
29
  NUMBER_DESCRIPTION =
@@ -26,7 +31,7 @@ NUMBER_DESCRIPTION =
26
31
  Number of password characters
27
32
  randpass -n 20 -l github rubygems
28
33
 
29
- ----------------------------------------
34
+ ----------------------------------
30
35
  DESC
31
36
 
32
37
  LIST_DESCRIPTION =
@@ -34,7 +39,7 @@ LIST_DESCRIPTION =
34
39
  Save list of passwords for given comments
35
40
  randpass -l GitHub GitLab StackOverflow
36
41
 
37
- ----------------------------------------
42
+ ----------------------------------
38
43
  DESC
39
44
 
40
45
  RANDOM_DESCRIPTION =
@@ -43,7 +48,13 @@ RANDOM_DESCRIPTION =
43
48
  randpass -r 5
44
49
  randpass -r 5 -n 25
45
50
 
46
- ----------------------------------------
51
+ ----------------------------------
52
+ DESC
53
+
54
+ PATH_DESCRIPTION =
55
+ <<~DESC
56
+ Path to directory where to save password list
57
+ default: gem directory
47
58
  DESC
48
59
 
49
60
  CLIPBOARD_DESCRIPTION =
@@ -53,19 +64,15 @@ CLIPBOARD_DESCRIPTION =
53
64
 
54
65
  NO_COPY_DESCRIPTION =
55
66
  <<~DESC
56
- Do not copy password into clipboard
67
+ Do not copy password to clipboard
57
68
  DESC
58
69
 
59
70
  NO_PRINT_DESCRIPTION =
60
71
  <<~DESC
61
- Do not print output in stdout
72
+ Do not print output to stdout
62
73
  DESC
63
74
 
64
-
65
- module Output
66
-
67
- def self.[](txt)
68
- STDOUT.puts(txt) unless Randpass.noprint?
69
- Clipboard.copy(txt) unless Randpass.nocopy?
70
- end
71
- end
75
+ NO_SAVE_DESCRIPTION =
76
+ <<~DESC
77
+ Do not save list output as txt file
78
+ DESC
data/bin/randpass CHANGED
@@ -1,67 +1,67 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative './options'
4
+ require_relative 'output'
5
+ require_relative 'setup_gem'
5
6
 
6
7
  opts = Optimist.options do
7
-
8
8
  banner BANNER
9
9
 
10
- opt :setup, SETUP_DESCRIPTION, short: 's', long: 'gem-setup'
11
- opt :num, NUMBER_DESCRIPTION, short: 'n', long: 'no', type: :integer
10
+ opt :num, NUMBER_DESCRIPTION, short: 'n', long: 'char', type: :integer
12
11
  opt :list, LIST_DESCRIPTION, short: 'l', long: 'list', type: :strings
13
12
  opt :random, RANDOM_DESCRIPTION, short: 'r', long: 'random', type: :integer
14
- opt :clear, CLIPBOARD_DESCRIPTION, short: 'c', long: 'clear', default: false
15
- opt :nocopy, NO_COPY_DESCRIPTION, short: 'd', long: 'noc', default: false
16
- opt :noprint, NO_PRINT_DESCRIPTION, short: 'o', long: 'nop', default: false
13
+ opt :path, PATH_DESCRIPTION, short: 'd', long: 'dir', type: :string
14
+ opt :clear, CLIPBOARD_DESCRIPTION, short: 'k', long: 'clear', default: false
15
+ opt :nocopy, NO_COPY_DESCRIPTION, short: 'c', long: 'noc', default: false
16
+ opt :noprint, NO_PRINT_DESCRIPTION, short: 'p', long: 'nop', default: false
17
+ opt :nosave, NO_SAVE_DESCRIPTION, short: 's', long: 'nos', default: false
18
+
19
+ opt :setup, SETUP_DESCRIPTION, short: 'i', long: 'gem-install'
17
20
 
18
- version "Randpass #{Randpass::VERSION}"
21
+ version "Randpass version #{Randpass::VERSION}"
19
22
  end
20
23
 
21
24
  if opts[:setup]
22
25
 
23
- dir = File.expand_path(__FILE__).gsub('/bin/randpass', '')
24
- Dir.chdir dir
25
- system 'bin/setup'
26
+ UserOS.gem_init
26
27
  exit(1)
27
28
 
28
29
  else
29
30
  require_relative '../lib/randpass'
30
31
  require 'clipboard'
31
32
 
32
-
33
33
  (Clipboard.clear && exit(1)) if opts[:clear]
34
34
 
35
- Randpass.nocopy! if opts[:nocopy]
35
+ Randpass.path = opts[:path] if opts[:path]
36
+
37
+ Randpass.nocopy! if opts[:nocopy]
38
+ Randpass.nosave! if opts[:nosave]
36
39
  Randpass.noprint! if opts[:noprint]
37
40
 
38
- case
39
- when opts[:num] && opts[:random]
40
- Randpass.generate_list opts[:num], list: opts[:random]
41
+ if opts[:list] && opts[:num]
42
+ Randpass.generate_list opts[:num].to_i, comments: opts[:list]
41
43
  Output[Randpass.storage]
42
- exit(1)
43
44
 
44
- when opts[:random]
45
- Randpass.generate_list nil, list: opts[:random]
45
+ elsif opts[:list]
46
+ Randpass.generate_list nil, comments: opts[:list]
46
47
  Output[Randpass.storage]
47
- exit(1)
48
48
 
49
- when opts[:list] && opts[:num]
50
- Randpass.generate_list opts[:num].to_i, comments: opts[:list]
49
+ elsif opts[:num] && opts[:random]
50
+ Randpass.generate_list opts[:num], list: opts[:random]
51
51
  Output[Randpass.storage]
52
- exit(1)
53
52
 
54
- when opts[:list]
55
- Randpass.generate_list nil, comments: opts[:list]
53
+ elsif opts[:random]
54
+ Randpass.generate_list nil, list: opts[:random]
56
55
  Output[Randpass.storage]
57
- exit(1)
58
56
 
59
- when ARGV.empty?
60
- Output[Randpass[20]] && exit(1)
61
- exit(1)
57
+ elsif opts[:num]
58
+ Output[Randpass[opts[:num]]]
59
+
60
+ elsif ARGV.empty?
61
+ Output[Randpass[20]]
62
62
 
63
- when ARGV.size == 1
63
+ elsif ARGV.size == 1
64
64
  Output[Randpass[ARGV[0].to_i]]
65
- exit(1)
66
65
  end
67
- end
66
+
67
+ end # if opts[:setup]
data/bin/setup CHANGED
@@ -3,31 +3,22 @@ set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
 
5
5
  function install_clipboard_dependency() {
6
-
7
6
  if !(command -v xsel) >/dev/null 2>&1; then
8
-
9
- echo "xsel was not found on the system, looking for xclip..."
7
+ echo "Xsel was not found on the system..."
10
8
 
11
9
  if !(command -v xclip) >/dev/null 2>&1; then
12
-
13
- echo "xclip also not found, installing xsell..."
10
+ echo "Xclip also not found, installing Xsell..."
11
+ sudo apt update -y -qq
14
12
  sudo apt install xsel -y
15
13
 
16
14
  else
17
- echo "but xclip was"
15
+ echo "but Xclip was"
18
16
  fi
19
-
17
+
20
18
  else
21
- echo "xsel found on the system"
19
+ echo "Xsel found on the system"
22
20
  fi
23
21
  }
24
22
 
25
- echo -e -n "Type 'w' if you are on Windows system, otherwise press enter: "
26
- read linux_key
27
-
28
- if [ "$linux_key" == "w" ] || [ "$linux_key" == "W" ]; then
29
- bundle install
30
- else
31
- install_clipboard_dependency
32
- bundle install
33
- fi
23
+ install_clipboard_dependency
24
+ bundle install
data/bin/setup_gem.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Helper module for gem installation
4
+ module UserOS
5
+ GEM_ROOT = File.expand_path(__FILE__).gsub('/bin/setup_gem.rb', '')
6
+
7
+ class << self
8
+ def windows?
9
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
10
+ end
11
+
12
+ def mac?
13
+ (/darwin/ =~ RUBY_PLATFORM) != nil
14
+ end
15
+
16
+ def linux?
17
+ !windows? && !mac?
18
+ end
19
+
20
+ # Call setup script based on user OS, if randpass is not installed
21
+ def gem_init
22
+ if system('bin/randpass --version')
23
+ puts 'was found on the system'
24
+ return
25
+ end
26
+ Dir.chdir GEM_ROOT
27
+ linux? ? system('bin/setup') : system('bundle install')
28
+ end
29
+ end
30
+ end
@@ -2,32 +2,16 @@
2
2
 
3
3
  require 'securerandom'
4
4
 
5
- # Generate random password with SecureRandom#base64 and a few
6
- # random special characters. Method #randpass is defined as
7
- # class and instance method, so you can call it or include it.
8
- #
9
5
  module Randpass
10
-
11
- # Allowed specials. xxx is just a flag for #add_special_chars
6
+ # Allowed specials (xxx is just a skip-flag)
12
7
  ARRAY = %w[! # * $ % _ @ xxx].freeze
13
8
 
14
- # Random number of times try to add random special character.
15
- # Transform to array, shuffle, and join back to string.
16
- #
17
- # Provide number of characters for password as argument,
18
- # default value is **25**.
19
- #
20
- # @param [Integer] chars_no Optional. Number of password characters.
21
- # @return [String]
22
- #
23
- def randpass(chars_no = nil)
24
- Randpass[chars_no]
25
- end
26
-
27
-
28
9
  class << self
29
-
10
+ # Generate random password
11
+ #
12
+ # @param [Integer] chars_no Optional. Number of password characters. Default: 25.
30
13
  # @return [String]
14
+ #
31
15
  def randpass(chars_no = nil)
32
16
 
33
17
  chars_no = 25 if [nil, 0, 1].include?(chars_no)
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'tempfile'
4
3
  require 'fileutils'
5
4
 
6
5
  module Randpass
@@ -9,22 +8,30 @@ module Randpass
9
8
 
10
9
  attr_accessor :path
11
10
 
12
- FILE_PATH = File.expand_path(__FILE__).gsub('/lib/randpass/storage.rb', '')
13
-
14
- # Add password to file
15
- # @param [String] pass **Required**. Add password to list
16
- # @param [String] comm Optional. Comment to write with password
11
+ # Add password to list
12
+ # @param [String] pass **Required**. Password
13
+ # @param [String] comm Optional. Password comment
17
14
  #
18
15
  def add(pass, comm = nil)
19
- storage_init unless @initialized
20
- @temp << "#{comm}: " unless comm.nil?
21
- @temp << pass
22
- @temp << "\n"
16
+ reload unless @initialized
17
+ line = comm.nil? ? pass : "#{comm}: #{pass}"
18
+ @temp << line
23
19
  end
24
-
25
- # Write list as .txt file
20
+
21
+ # Clear old password list
22
+ def reload
23
+ @path ||= Dir.pwd
24
+ @temp = Array.new
25
+ @initialized = true
26
+ end
27
+
28
+ # Save list of passwords as txt file
26
29
  def finalize
27
- File.write "#{@path}/randpass_#{Time.now.to_i}.txt", @temp
30
+ unless Randpass.nosave?
31
+ temp = @temp.join "\n"
32
+ @path += '/' unless @path.end_with?('/')
33
+ File.write "#{@path}randpass_#{Time.now.to_i}.txt", temp
34
+ end
28
35
  @initialized = false
29
36
  end
30
37
 
@@ -37,8 +44,6 @@ module Randpass
37
44
  # @option opts [Integer] list Number of passwords to generate (if no comments)
38
45
  #
39
46
  def generate_list(chars_no, opts = {list: 10})
40
- storage_init unless initialized?
41
-
42
47
  if opts[:comments].nil?
43
48
  opts[:list].times do
44
49
  add Randpass[chars_no]
@@ -62,13 +67,5 @@ module Randpass
62
67
 
63
68
  def initialized?; @initialized == true end
64
69
 
65
- def storage_init
66
- @path ||= FILE_PATH
67
- Dir.chdir @path
68
- @temp = String.new
69
- @initialized = true
70
- end
71
-
72
- alias :init_storage :storage_init
73
70
  end
74
- end
71
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Randpass
4
4
  # gem version
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
data/lib/randpass.rb CHANGED
@@ -4,31 +4,41 @@ require_relative 'randpass/version'
4
4
  require_relative 'randpass/random'
5
5
  require_relative 'randpass/storage'
6
6
 
7
+ # Generate random password with SecureRandom#base64 and a few
8
+ # special characters.
9
+ #
7
10
  module Randpass
8
11
 
9
12
  class << self
10
13
 
11
- @output = true
12
- @copy = true
13
-
14
-
14
+ # Check if password(s) will be copied to clipboard
15
15
  def nocopy?
16
16
  @copy == false
17
17
  end
18
18
 
19
-
19
+ # Disable password(s) copy (affect only executable)
20
20
  def nocopy!
21
21
  @copy = false
22
22
  end
23
23
 
24
-
24
+ # Check if password(s) will be printed to STDOUT
25
25
  def noprint?
26
26
  @output == false
27
27
  end
28
28
 
29
-
29
+ # Do not print password(s) to STDOUT (affect only executable)
30
30
  def noprint!
31
31
  @output = false
32
32
  end
33
+
34
+ # Check if password list will be saved as txt file.
35
+ def nosave?
36
+ @save == false
37
+ end
38
+
39
+ # Do not save password list as txt file.
40
+ def nosave!
41
+ @save = false
42
+ end
33
43
  end
34
44
  end
data/randpass.gemspec CHANGED
@@ -7,9 +7,8 @@ Gem::Specification.new do |s|
7
7
  s.version = Randpass::VERSION
8
8
  s.summary = 'Ruby random password generator'
9
9
  s.description = <<~DESCRIPTION
10
- Generate single password or list, with or without comments,
11
- and copy password in clipboard (or not). Password is generated with
12
- SecureRandom#base64 + random special characters.
10
+ Ruby random password generator. Allow single password or list, comments,
11
+ use of clipboard and/or STDOUT.
13
12
  DESCRIPTION
14
13
 
15
14
  s.license = 'MIT'
@@ -31,7 +30,8 @@ Gem::Specification.new do |s|
31
30
  lib/randpass/version.rb
32
31
  lib/randpass/random.rb
33
32
  lib/randpass/storage.rb
34
- bin/options.rb
33
+ bin/setup_gem.rb
34
+ bin/output.rb
35
35
  bin/setup
36
36
  LICENSE
37
37
  README.md
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: randpass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - alx3dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-15 00:00:00.000000000 Z
11
+ date: 2022-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -67,9 +67,8 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '13.0'
69
69
  description: |
70
- Generate single password or list, with or without comments,
71
- and copy password in clipboard (or not). Password is generated with
72
- SecureRandom#base64 + random special characters.
70
+ Ruby random password generator. Allow single password or list, comments,
71
+ use of clipboard and/or STDOUT.
73
72
  email:
74
73
  executables:
75
74
  - randpass
@@ -78,9 +77,10 @@ extra_rdoc_files: []
78
77
  files:
79
78
  - LICENSE
80
79
  - README.md
81
- - bin/options.rb
80
+ - bin/output.rb
82
81
  - bin/randpass
83
82
  - bin/setup
83
+ - bin/setup_gem.rb
84
84
  - lib/randpass.rb
85
85
  - lib/randpass/random.rb
86
86
  - lib/randpass/storage.rb
@@ -94,7 +94,7 @@ metadata:
94
94
  source_code_uri: https://github.com/alx3dev/randpass
95
95
  bug_tracker_uri: https://github.com/alx3dev/randpass/issues
96
96
  changelog_uri: https://github.com/alx3dev/randpass/changelog.md
97
- documentation_uri: https://rubydoc.info/gems/randpass/0.2.0
97
+ documentation_uri: https://rubydoc.info/gems/randpass/0.3.0
98
98
  rubygems_mfa_required: 'true'
99
99
  post_install_message:
100
100
  rdoc_options: []
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  requirements: []
117
- rubygems_version: 3.3.3
117
+ rubygems_version: 3.3.26
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Ruby random password generator