password_util 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/password_util.rb +101 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 585b4336af1d3cc4191a8f5ae5e5fa9f820dcc28aaaa6e4c4d90215436825c51
|
4
|
+
data.tar.gz: c553b39e03316a0882d05daac8463b8c75779ab2ef2dc99a4bc27d84cf8cb33f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3cd8c25a9a87be821e22fd6eaf68ba8742531c44a955f4ad69c3036da41359f1f6e91afc987ca4b9d2d8b290047962a9e695232689f8d1a30268622c55ed54fe
|
7
|
+
data.tar.gz: d8fa4ca0218c83b99d321328f9b35e08c1c89330c32f39163a7d735e30f3ace975ac01ca18000f7bc474456356950b9b3e0a46522495bcb1a4a9c3c7eb22d0c4
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module PasswordUtil
|
2
|
+
class ConfigurationError < StandardError; end
|
3
|
+
|
4
|
+
UPPER_LETTERS = ('A'..'Z').to_a.freeze
|
5
|
+
LOWER_LETTERS = ('a'..'z').to_a.freeze
|
6
|
+
NUMBERS = ('0'..'9').to_a.freeze
|
7
|
+
SYMBOLS = %w[~ ` ! @ # $ % ^ & * ( ) _ - + = { \[ } \] | \\ : ; " ' < , > . ? /].freeze
|
8
|
+
|
9
|
+
def self.validate_config!
|
10
|
+
boolean_classes = [TrueClass, FalseClass]
|
11
|
+
|
12
|
+
raise ConfigurationError, 'password_length: expected Integer' unless password_length.is_a?(Integer)
|
13
|
+
raise ConfigurationError, 'has_lower_letters: expected Boolean' unless boolean_classes.include?(has_lower_letters.class)
|
14
|
+
raise ConfigurationError, 'min_lower_letters: expected Integer' unless min_lower_letters.is_a?(Integer)
|
15
|
+
raise ConfigurationError, 'has_upper_letters: expected Boolean' unless boolean_classes.include?(has_upper_letters.class)
|
16
|
+
raise ConfigurationError, 'min_upper_letters: expected Integer' unless min_upper_letters.is_a?(Integer)
|
17
|
+
raise ConfigurationError, 'has_numbers: expected Boolean' unless boolean_classes.include?(has_numbers.class)
|
18
|
+
raise ConfigurationError, 'min_numbers: expected Integer' unless min_numbers.is_a?(Integer)
|
19
|
+
raise ConfigurationError, 'has_symbols: expected Boolean' unless boolean_classes.include?(has_symbols.class)
|
20
|
+
raise ConfigurationError, 'min_symbols: expected Integer' unless min_symbols.is_a?(Integer)
|
21
|
+
|
22
|
+
raise ConfigurationError, 'No usable character set.' unless has_lower_letters || has_upper_letters || has_numbers || has_symbols
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.reset_config
|
26
|
+
self.password_length = 8
|
27
|
+
self.has_lower_letters = true
|
28
|
+
self.min_lower_letters = 1
|
29
|
+
self.has_upper_letters = true
|
30
|
+
self.min_upper_letters = 1
|
31
|
+
self.has_numbers = true
|
32
|
+
self.min_numbers = 1
|
33
|
+
self.has_symbols = true
|
34
|
+
self.min_symbols = 1
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.generate
|
38
|
+
validate_config!
|
39
|
+
charset = []
|
40
|
+
password = []
|
41
|
+
|
42
|
+
if has_lower_letters
|
43
|
+
charset << LOWER_LETTERS
|
44
|
+
min_lower_letters.times do
|
45
|
+
password << LOWER_LETTERS.sample
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
if has_upper_letters
|
50
|
+
charset << UPPER_LETTERS
|
51
|
+
min_upper_letters.times do
|
52
|
+
password << UPPER_LETTERS.sample
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if has_numbers
|
57
|
+
charset << NUMBERS
|
58
|
+
min_numbers.times do
|
59
|
+
password << NUMBERS.sample
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
if has_symbols
|
64
|
+
charset << SYMBOLS
|
65
|
+
min_symbols.times do
|
66
|
+
password << SYMBOLS.sample
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
password.shuffle!
|
71
|
+
password << charset.sample.sample while password.length < password_length
|
72
|
+
password.join('')[0...password_length]
|
73
|
+
end
|
74
|
+
|
75
|
+
singleton_class.attr_accessor :password_length
|
76
|
+
self.password_length = 8
|
77
|
+
|
78
|
+
singleton_class.attr_accessor :has_lower_letters
|
79
|
+
self.has_lower_letters = true
|
80
|
+
|
81
|
+
singleton_class.attr_accessor :min_lower_letters
|
82
|
+
self.min_lower_letters = 1
|
83
|
+
|
84
|
+
singleton_class.attr_accessor :has_upper_letters
|
85
|
+
self.has_upper_letters = true
|
86
|
+
|
87
|
+
singleton_class.attr_accessor :min_upper_letters
|
88
|
+
self.min_upper_letters = 1
|
89
|
+
|
90
|
+
singleton_class.attr_accessor :has_numbers
|
91
|
+
self.has_numbers = true
|
92
|
+
|
93
|
+
singleton_class.attr_accessor :min_numbers
|
94
|
+
self.min_numbers = 1
|
95
|
+
|
96
|
+
singleton_class.attr_accessor :has_symbols
|
97
|
+
self.has_symbols = true
|
98
|
+
|
99
|
+
singleton_class.attr_accessor :min_symbols
|
100
|
+
self.min_symbols = 1
|
101
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: password_util
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Reinier John Avila
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-11-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Different password related utility tool.
|
14
|
+
email: reinieravila@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/password_util.rb
|
20
|
+
homepage: https://github.com/reinieravila/password_util.git
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.7.0
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.3.7
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Password Utility Tool
|
43
|
+
test_files: []
|