randpass 0.1.1 → 0.1.2
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 +27 -2
- data/lib/randpass/random.rb +25 -8
- data/lib/randpass/version.rb +2 -1
- data/lib/randpass.rb +0 -4
- data/randpass.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64d1df5909d0a6d92321fddb99e997280e97ca98b02b96ba58e3a22e95ba6ff1
|
4
|
+
data.tar.gz: 020db401b7394baf1edeb26c224bba110ea61216dd5d2f0b56df8486fe5b8ed5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a38b3a3e9d8f19ef6759b5d031b7f41a657930d98bf56835887cc1b6e789ba8d3a0dfc03ba1d4bb5db46efaebc39a79cc2e936ba04d4f8d7de3e130b2c681e5
|
7
|
+
data.tar.gz: 728d609352f004349c6bb8a8c62101973378febfe200f815c4a8ac30d9c5c30f7a433c022d02827123106aaf4d588e933afec61ece7da14817e762dac65ce31c
|
data/README.md
CHANGED
@@ -5,23 +5,29 @@ Create random password with ruby. Use `SecureRandom#base64` + few random special
|
|
5
5
|
## How to install
|
6
6
|
|
7
7
|
- install from rubygems
|
8
|
+
|
8
9
|
```
|
9
10
|
gem install randpass
|
10
11
|
```
|
11
12
|
- download from github with ssh
|
13
|
+
|
12
14
|
```
|
13
15
|
git clone git@github.com:alx3dev/randpass \
|
14
16
|
cd randpass && bundle install
|
15
17
|
```
|
16
18
|
- download from github with https
|
19
|
+
|
17
20
|
```
|
18
21
|
git clone https://www.github.com/alx3dev/randpass \
|
19
22
|
cd randpass && bundle install
|
20
23
|
```
|
21
24
|
|
25
|
+
To build your own gem, run `rake bundle`, and install it locally with `gem install pkg/randpass-0.1.1.gem`
|
26
|
+
|
22
27
|
## How to use:
|
23
28
|
|
24
29
|
- use from terminal
|
30
|
+
|
25
31
|
```
|
26
32
|
# default 18 characters
|
27
33
|
randpass
|
@@ -31,10 +37,11 @@ randpass
|
|
31
37
|
randpass 30
|
32
38
|
=> zBv2BXVB/X2WJMqzSE%VRe#Sg!/0_wYpvJC1gyHU
|
33
39
|
|
34
|
-
#
|
40
|
+
# install from rubygems, or build your own version, otherwise you need to run:
|
35
41
|
bin/randpass
|
36
42
|
```
|
37
43
|
- use as library
|
44
|
+
|
38
45
|
```ruby
|
39
46
|
require 'randpass'
|
40
47
|
|
@@ -43,4 +50,22 @@ Randpass[20]
|
|
43
50
|
Randpass.randpass 20
|
44
51
|
=> "0!ZNiAUZCbjo!#hHeX+XX$eAC=!p"
|
45
52
|
```
|
46
|
-
|
53
|
+
|
54
|
+
Randpass is a module with both class and instance methods `#randpass`, so you can include/extend it in your class.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
require 'randpass'
|
58
|
+
include Randpass
|
59
|
+
|
60
|
+
class MyClass
|
61
|
+
def some_method
|
62
|
+
random_string = randpass 33
|
63
|
+
end
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
Tested on:
|
68
|
+
- ruby `2.7.5`
|
69
|
+
- ruby `3.0.3`
|
70
|
+
- ruby `3.1.0-preview1`
|
71
|
+
- jruby `9.3.2.0`
|
data/lib/randpass/random.rb
CHANGED
@@ -2,20 +2,35 @@
|
|
2
2
|
|
3
3
|
require 'securerandom'
|
4
4
|
|
5
|
-
# Generate random password with base64 and few
|
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
|
+
# @note Always shuffle #base64 if it has less than 16 chars, because they end with '=='
|
6
10
|
#
|
7
11
|
module Randpass
|
12
|
+
#
|
13
|
+
# Random number of times try to add random special character.
|
14
|
+
# Transform to array, shuffle, and join back to string
|
15
|
+
#
|
16
|
+
# @param [Integer] number_of_chars **Required**. Number of password characters.
|
17
|
+
# @return [String]
|
18
|
+
#
|
19
|
+
def randpass(number_of_chars)
|
20
|
+
Randpass[number_of_chars]
|
21
|
+
end
|
22
|
+
|
8
23
|
class << self
|
9
|
-
#
|
10
|
-
|
11
|
-
# @note Always shuffle #base64 if it has less than 16 chars, because they end with '=='
|
12
|
-
#
|
13
|
-
def [](number_of_chars = 18)
|
24
|
+
# @return [String]
|
25
|
+
def randpass(number_of_chars)
|
14
26
|
param = SecureRandom.base64(number_of_chars)
|
15
|
-
rand(5..10).times
|
27
|
+
rand(5..10).times do
|
28
|
+
param = add_special_chars(param)
|
29
|
+
end
|
16
30
|
param.split('').shuffle.join
|
17
31
|
end
|
18
|
-
|
32
|
+
|
33
|
+
alias [] randpass
|
19
34
|
|
20
35
|
private
|
21
36
|
|
@@ -24,6 +39,7 @@ module Randpass
|
|
24
39
|
# bigger number than options - we don't want
|
25
40
|
# same number of special chars each time
|
26
41
|
count = SecureRandom.random_number 15_000
|
42
|
+
|
27
43
|
char = case count
|
28
44
|
when 1...1000 then '_'
|
29
45
|
when 1000...2000 then '!'
|
@@ -33,6 +49,7 @@ module Randpass
|
|
33
49
|
when 6000...7000 then '?'
|
34
50
|
else return param
|
35
51
|
end
|
52
|
+
|
36
53
|
param[rand(param.size)] = char
|
37
54
|
param
|
38
55
|
end
|
data/lib/randpass/version.rb
CHANGED
data/lib/randpass.rb
CHANGED
data/randpass.gemspec
CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
README.md
|
34
34
|
randpass.gemspec]
|
35
35
|
|
36
|
-
s.required_ruby_version = '>= 2.
|
36
|
+
s.required_ruby_version = '>= 2.6', '< 3.2'
|
37
37
|
|
38
38
|
s.add_development_dependency 'bundler', '~> 2.3'
|
39
39
|
s.add_development_dependency 'rake', '~> 13.0'
|
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.2
|
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-
|
11
|
+
date: 2022-02-21 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.2
|
66
66
|
rubygems_mfa_required: 'true'
|
67
67
|
post_install_message:
|
68
68
|
rdoc_options: []
|
@@ -72,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '2.
|
75
|
+
version: '2.6'
|
76
76
|
- - "<"
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '3.2'
|