randpass 0.1.2 → 0.1.3

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: 64d1df5909d0a6d92321fddb99e997280e97ca98b02b96ba58e3a22e95ba6ff1
4
- data.tar.gz: 020db401b7394baf1edeb26c224bba110ea61216dd5d2f0b56df8486fe5b8ed5
3
+ metadata.gz: 56fe4a3d0922ef73687911332685af59657369380b77514e533ede43854cee86
4
+ data.tar.gz: 6f9adf346eb9fc6339964201aee71563ec41ce7b3c68b8e4a82fbaa90c94e924
5
5
  SHA512:
6
- metadata.gz: 1a38b3a3e9d8f19ef6759b5d031b7f41a657930d98bf56835887cc1b6e789ba8d3a0dfc03ba1d4bb5db46efaebc39a79cc2e936ba04d4f8d7de3e130b2c681e5
7
- data.tar.gz: 728d609352f004349c6bb8a8c62101973378febfe200f815c4a8ac30d9c5c30f7a433c022d02827123106aaf4d588e933afec61ece7da14817e762dac65ce31c
6
+ metadata.gz: 938d2f69909daca1f9488c8ea23837a29caa25a995039a7b526e6a1d9c5ce66035fde1a62135544f52950028e55c952cc8b8aa077f8ed4b68d9521a5c914ba15
7
+ data.tar.gz: b7ec2a62282de7423cc955b4073fd0acf9a43dc7494721a6bc7b111a753557de8b5bac6b9b90e71a947f633f5285bc579549329a139b3e8b554d6040d568dc5e
data/README.md CHANGED
@@ -22,20 +22,20 @@ git clone https://www.github.com/alx3dev/randpass \
22
22
  cd randpass && bundle install
23
23
  ```
24
24
 
25
- To build your own gem, run `rake bundle`, and install it locally with `gem install pkg/randpass-0.1.1.gem`
25
+ To build your own gem, run `rake bundle`, and install it locally with `gem install pkg/randpass-0.1.3.gem`
26
26
 
27
27
  ## How to use:
28
28
 
29
29
  - use from terminal
30
30
 
31
31
  ```
32
- # default 18 characters
32
+ # default 22 characters
33
33
  randpass
34
- => 3!J_GApnCy4Mor1hMPbI?LhT
34
+ => W4fkGVdXx6pzk$O?VP11!wWs
35
35
 
36
36
  # or add number of characters as argument
37
- randpass 30
38
- => zBv2BXVB/X2WJMqzSE%VRe#Sg!/0_wYpvJC1gyHU
37
+ randpass 33
38
+ => etkK$YW1R_PXK8FsjnGHr+%w2cTBbMTOTej3s8je?2ya
39
39
 
40
40
  # install from rubygems, or build your own version, otherwise you need to run:
41
41
  bin/randpass
@@ -48,7 +48,7 @@ require 'randpass'
48
48
  Randpass[20]
49
49
  # or
50
50
  Randpass.randpass 20
51
- => "0!ZNiAUZCbjo!#hHeX+XX$eAC=!p"
51
+ => "1L3Jk$S850Np=ikQ7zeqb44qaBC9"
52
52
  ```
53
53
 
54
54
  Randpass is a module with both class and instance methods `#randpass`, so you can include/extend it in your class.
data/bin/randpass CHANGED
@@ -4,7 +4,7 @@
4
4
  require_relative '../lib/randpass'
5
5
 
6
6
  pass = if ARGV.empty?
7
- Randpass[18]
7
+ Randpass[22]
8
8
  else
9
9
  Randpass.randpass ARGV[0].to_i
10
10
  end
@@ -6,27 +6,33 @@ require 'securerandom'
6
6
  # random special characters. Method #randpass is defined as
7
7
  # class and instance method, so you can call it or include it.
8
8
  #
9
- # @note Always shuffle #base64 if it has less than 16 chars, because they end with '=='
10
- #
11
9
  module Randpass
12
- #
10
+ # Allowed specials. xxx is just a flag for #add_special_chars
11
+ ARRAY = %w[! # * $ % _ @ xxx].freeze
12
+
13
13
  # Random number of times try to add random special character.
14
- # Transform to array, shuffle, and join back to string
14
+ # Transform to array, shuffle, and join back to string.
15
+ #
16
+ # Provide number of characters for password as argument,
17
+ # default value is **22**.
15
18
  #
16
- # @param [Integer] number_of_chars **Required**. Number of password characters.
19
+ # @param [Integer] number_of_chars Optional. Number of password characters.
17
20
  # @return [String]
18
21
  #
19
- def randpass(number_of_chars)
22
+ def randpass(number_of_chars = nil)
20
23
  Randpass[number_of_chars]
21
24
  end
22
25
 
23
26
  class << self
24
27
  # @return [String]
25
- def randpass(number_of_chars)
26
- param = SecureRandom.base64(number_of_chars)
27
- rand(5..10).times do
28
- param = add_special_chars(param)
28
+ def randpass(number_of_chars = 20)
29
+ # slice string made with base64, to number of characters we want
30
+ param = SecureRandom.base64(number_of_chars)[0...number_of_chars]
31
+
32
+ rand(param.size / 2).times do
33
+ param = add_special_characters(param)
29
34
  end
35
+
30
36
  param.split('').shuffle.join
31
37
  end
32
38
 
@@ -34,25 +40,12 @@ module Randpass
34
40
 
35
41
  private
36
42
 
37
- # rubocop:disable Metrics/MethodLength
38
- def add_special_chars(param)
39
- # bigger number than options - we don't want
40
- # same number of special chars each time
41
- count = SecureRandom.random_number 15_000
42
-
43
- char = case count
44
- when 1...1000 then '_'
45
- when 1000...2000 then '!'
46
- when 2000...3000 then '#'
47
- when 3000...4000 then '$'
48
- when 4000...5000 then '%'
49
- when 6000...7000 then '?'
50
- else return param
51
- end
52
-
53
- param[rand(param.size)] = char
43
+ def add_special_characters(param)
44
+ char = ARRAY.shuffle[rand(ARRAY.size)]
45
+ return param if char == 'xxx'
46
+
47
+ param[rand(param.size)] = char.to_s
54
48
  param
55
49
  end
56
- # rubocop:enable Metrics/MethodLength
57
50
  end
58
51
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Randpass
4
4
  # gem version
5
- VERSION = '0.1.2'
5
+ VERSION = '0.1.3'
6
6
  end
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - alx3dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-21 00:00:00.000000000 Z
11
+ date: 2022-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,7 +62,7 @@ metadata:
62
62
  source_code_uri: https://github.com/alx3dev/randpass
63
63
  bug_tracker_uri: https://github.com/alx3dev/randpass/issues
64
64
  changelog_uri: https://github.com/alx3dev/randpass/changelog.md
65
- documentation_uri: https://rubydoc.info/gems/randpass/0.1.2
65
+ documentation_uri: https://rubydoc.info/gems/randpass/0.1.3
66
66
  rubygems_mfa_required: 'true'
67
67
  post_install_message:
68
68
  rdoc_options: []