readable_password_generator 0.0.1
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 +7 -0
- data/lib/readable_password_generator.rb +67 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4e508c49dffefe996de7f6bd6f99f04648a06069e15b8760232abfc1baaf47f5
|
4
|
+
data.tar.gz: 242760e7d968523ccde40c9d21ae1ba1e41de9e49a5ea55cfc71445f09b6d5d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a1c40bf1b64b026c1a6fb2eb4d3fbc2247688d97164017cd8c044abe0ce0bfb73f0987ab585a51c4175c46b7a637e8952740056ab4cfdcd0318b60b1b67a780
|
7
|
+
data.tar.gz: b150ebee4e4fac88afba2586aba9e35f950c424f3ba973224571d196784d4e8c72b890e59b3bf3021a78fd397dc613dc77def7ea5493218b8c09d4aeca73fd2f
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class Password
|
2
|
+
|
3
|
+
#minimum default length is set to 10 by security concerns of a readable password
|
4
|
+
DEFAULT_PW_LENGTH = [10,11,12,13,14,15,16,17,18]
|
5
|
+
|
6
|
+
attr_accessor :pw_length
|
7
|
+
|
8
|
+
def initialize(a_pw_length = DEFAULT_PW_LENGTH.sample)
|
9
|
+
@pw_length = check_length_value(a_pw_length) #checking on password length value
|
10
|
+
@vowel_pos = 0 # by default start password with a vowel
|
11
|
+
end
|
12
|
+
|
13
|
+
#generate password of a required length
|
14
|
+
def gener_passw
|
15
|
+
#set position for a vowel: either to start a password with it first or not:
|
16
|
+
# 0 - start password with a vowel
|
17
|
+
# 1 - start password with a consonat(s)
|
18
|
+
@vowel_pos = [1, 2].sample
|
19
|
+
size, result = @pw_length, ""
|
20
|
+
count = 0
|
21
|
+
size.times do |char|
|
22
|
+
count = 0 if count==2
|
23
|
+
count+=1
|
24
|
+
result << take_char(count)
|
25
|
+
end
|
26
|
+
return result = result[0...size]
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
#sets of character used in generating
|
32
|
+
VOWELS = %w(a e i o u y)
|
33
|
+
CONSONANTS = %w(b c d f g h j k l m n p r s t v w x z)
|
34
|
+
#to diversify the end result
|
35
|
+
DOUBLE_CONSONANTS = %w(ch cr fr nd ng nk nt ph pr rd sh sl sp st th tr)
|
36
|
+
|
37
|
+
#take a sample char from a set of letters
|
38
|
+
def take_char(set_type)
|
39
|
+
if set_type == @vowel_pos
|
40
|
+
return VOWELS.sample
|
41
|
+
else
|
42
|
+
#prioritize randomness to choosing CONSONANTS over DOUBLE_CONSONANTS (3:1)
|
43
|
+
if [1,2,3,4].sample == 4
|
44
|
+
return CONSONANTS.sample
|
45
|
+
else
|
46
|
+
return DOUBLE_CONSONANTS.sample
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
#checking length value - does it meet specified criteria:
|
52
|
+
# - must consist of numeric value or numeric range
|
53
|
+
def check_length_value(a_pw_length)
|
54
|
+
if a_pw_length.is_a?(NilClass)
|
55
|
+
a_pw_length = DEFAULT_PW_LENGTH.sample
|
56
|
+
elsif a_pw_length.is_a?(Array)
|
57
|
+
a_pw_length = a_pw_length.sample
|
58
|
+
elsif a_pw_length.is_a?(Integer)
|
59
|
+
if (a_pw_length < 1) || (a_pw_length > 100)
|
60
|
+
raise ArgumentError, "Length cannot be #{a_pw_length}, length must be in range of 1-100!"
|
61
|
+
end
|
62
|
+
else
|
63
|
+
raise ArgumentError, "Length must be either an Integer or a Range value!\n#{a_pw_length.class} data type is given. "
|
64
|
+
end
|
65
|
+
return a_pw_length
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: readable_password_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vitaly Platonov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: viitaly.platonov@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/readable_password_generator.rb
|
20
|
+
homepage: http://rubygems.org/gems/readable_password_generator
|
21
|
+
licenses:
|
22
|
+
- GPL-3.0
|
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: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.7.7
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Generates readable passwords!
|
44
|
+
test_files: []
|