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 +4 -4
- data/README.md +6 -6
- data/bin/randpass +1 -1
- data/lib/randpass/random.rb +21 -28
- data/lib/randpass/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56fe4a3d0922ef73687911332685af59657369380b77514e533ede43854cee86
|
4
|
+
data.tar.gz: 6f9adf346eb9fc6339964201aee71563ec41ce7b3c68b8e4a82fbaa90c94e924
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
32
|
+
# default 22 characters
|
33
33
|
randpass
|
34
|
-
=>
|
34
|
+
=> W4fkGVdXx6pzk$O?VP11!wWs
|
35
35
|
|
36
36
|
# or add number of characters as argument
|
37
|
-
randpass
|
38
|
-
=>
|
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
|
-
=> "
|
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
data/lib/randpass/random.rb
CHANGED
@@ -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
|
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
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
data/lib/randpass/version.rb
CHANGED
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.
|
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-
|
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.
|
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: []
|