passweird 0.1.3 → 0.2.0
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/Gemfile.lock +1 -1
- data/lib/passweird/checker.rb +7 -3
- data/lib/passweird/leet_speak.rb +68 -17
- data/lib/passweird/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a90a6f24240691ccdd65ca1185eeda32e95dfc65302d1eb4fa118a5b8e45504
|
4
|
+
data.tar.gz: 463bf49ad884574607e5682bd00de52008fca4ee272e9a49f4723c846d306d1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 940795845301e0ca6c127c168b70b7731fbfba2c779a95bfacf56bdb830e3d1cedfbc79d95e846da41d558f763e7478402450c5fde7c5e24c524af6ef657d201
|
7
|
+
data.tar.gz: e20d91623ec83339f47f662f83787af532146c77964f67aa59f52c9ff584ef0d49ca825f33f588d870b803fb90ac17d6b65e0ed1b0d6ece93ffbcb8563289300
|
data/Gemfile.lock
CHANGED
data/lib/passweird/checker.rb
CHANGED
@@ -24,7 +24,7 @@ module Passweird
|
|
24
24
|
#
|
25
25
|
# @return [Boolean] true if the password is blacklisted, false otherwise
|
26
26
|
def blacklisted?
|
27
|
-
@blacklisted ||= BlacklistedTerm.
|
27
|
+
@blacklisted ||= BlacklistedTerm.exists?(term: possible_terms)
|
28
28
|
end
|
29
29
|
|
30
30
|
# Retrieves the blacklisted terms that match the possible terms
|
@@ -47,6 +47,10 @@ module Passweird
|
|
47
47
|
@all_substring_case_permutations ||= substrings + unleeted_substrings + downcased_substrings + upcased_substrings
|
48
48
|
end
|
49
49
|
|
50
|
+
def all_substrings
|
51
|
+
@all_substrings ||= (substrings + unleeted_substrings).uniq
|
52
|
+
end
|
53
|
+
|
50
54
|
def unleeted_substrings
|
51
55
|
@unleeted_substrings ||= LeetSpeak.unleet_all(substrings)
|
52
56
|
end
|
@@ -56,11 +60,11 @@ module Passweird
|
|
56
60
|
end
|
57
61
|
|
58
62
|
def downcased_substrings
|
59
|
-
@downcased_substrings ||=
|
63
|
+
@downcased_substrings ||= all_substrings.map(&:downcase)
|
60
64
|
end
|
61
65
|
|
62
66
|
def upcased_substrings
|
63
|
-
@upcased_substrings ||=
|
67
|
+
@upcased_substrings ||= all_substrings.map(&:upcase)
|
64
68
|
end
|
65
69
|
end
|
66
70
|
end
|
data/lib/passweird/leet_speak.rb
CHANGED
@@ -8,41 +8,92 @@ module Passweird
|
|
8
8
|
# leet_speak = Passweird::LeetSpeak.new("example")
|
9
9
|
# leet_string = leet_speak.leet
|
10
10
|
# # => "3x4mpl3"
|
11
|
-
# normal_string = leet_speak.
|
11
|
+
# normal_string = leet_speak.unleet
|
12
12
|
# # => "example"
|
13
13
|
class LeetSpeak
|
14
14
|
attr_reader :given_string
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
"
|
19
|
-
"
|
20
|
-
"
|
21
|
-
"
|
22
|
-
"
|
23
|
-
"
|
24
|
-
"
|
25
|
-
"
|
16
|
+
ALPHABET_TO_SIMPLE_LEET = {
|
17
|
+
# Uppercase
|
18
|
+
"A" => "4",
|
19
|
+
"B" => "8",
|
20
|
+
"C" => "(",
|
21
|
+
"E" => "3",
|
22
|
+
"F" => "ƒ",
|
23
|
+
"G" => "6",
|
24
|
+
"H" => "#",
|
25
|
+
"I" => "1",
|
26
|
+
"N" => "И",
|
27
|
+
"O" => "0",
|
28
|
+
"R" => "Я",
|
29
|
+
"S" => "5",
|
30
|
+
"T" => "7",
|
31
|
+
"U" => "U",
|
32
|
+
"Y" => "¥",
|
33
|
+
"Z" => "2",
|
34
|
+
# Downcase
|
35
|
+
"a" => "4",
|
36
|
+
"b" => "8",
|
37
|
+
"c" => "(",
|
38
|
+
"e" => "3",
|
39
|
+
"f" => "ƒ",
|
40
|
+
"g" => "6",
|
41
|
+
"h" => "#",
|
42
|
+
"i" => "1",
|
43
|
+
"n" => "и",
|
44
|
+
"o" => "0",
|
45
|
+
"r" => "я",
|
46
|
+
"s" => "5",
|
47
|
+
"t" => "7",
|
48
|
+
"u" => "u",
|
49
|
+
"y" => "¥",
|
50
|
+
"z" => "2"
|
26
51
|
}.freeze
|
27
52
|
|
53
|
+
# Reference: https://en.wikipedia.org/wiki/Leet#Table_of_leet-speak_substitutes_for_normal_letters
|
54
|
+
# Excluded leet speak equivalents that has 3 or more characters
|
55
|
+
LEET_TO_ALPHABET = {
|
56
|
+
"4" => "A", "@" => "A", "Д" => "A",
|
57
|
+
"8" => "B", "ß" => "B",
|
58
|
+
"(" => "C", "{" => "C",
|
59
|
+
"3" => "E", "£" => "E", "€" => "E",
|
60
|
+
"ƒ" => "F",
|
61
|
+
"6" => "G", "9" => "G",
|
62
|
+
"#" => "H",
|
63
|
+
"1" => "I", "!" => "I",
|
64
|
+
"И" => "N", "ท" => "N",
|
65
|
+
"0" => "O", "Ø" => "O",
|
66
|
+
"Я" => "R",
|
67
|
+
"5" => "S", "$" => "S",
|
68
|
+
"7" => "T",
|
69
|
+
"พ" => "W", "₩" => "W", "ω" => "W",
|
70
|
+
"¥" => "Y",
|
71
|
+
"2" => "Z"
|
72
|
+
}.freeze
|
73
|
+
|
74
|
+
|
28
75
|
def self.leet(given_string)
|
29
76
|
new(given_string).leet
|
30
77
|
end
|
31
78
|
|
79
|
+
def self.leet?(given_string)
|
80
|
+
new(given_string).leet?
|
81
|
+
end
|
82
|
+
|
32
83
|
def self.leet_all(array_of_strings)
|
33
84
|
raise ArgumentError, "array_of_strings must be an Array" unless array_of_strings.is_a?(Array)
|
34
85
|
|
35
86
|
array_of_strings.map { |string| leet(string) }
|
36
87
|
end
|
37
88
|
|
38
|
-
def self.
|
39
|
-
new(given_string).
|
89
|
+
def self.unleet(given_string)
|
90
|
+
new(given_string).unleet
|
40
91
|
end
|
41
92
|
|
42
93
|
def self.unleet_all(array_of_strings)
|
43
94
|
raise ArgumentError, "array_of_strings must be an Array" unless array_of_strings.is_a?(Array)
|
44
95
|
|
45
|
-
array_of_strings.map { |string|
|
96
|
+
array_of_strings.map { |string| unleet(string) }
|
46
97
|
end
|
47
98
|
|
48
99
|
def initialize(given_string)
|
@@ -55,7 +106,7 @@ module Passweird
|
|
55
106
|
#
|
56
107
|
# @return [String] the converted leet speak string
|
57
108
|
def leet
|
58
|
-
given_string.gsub(/[#{
|
109
|
+
given_string.gsub(/[#{ALPHABET_TO_SIMPLE_LEET.keys.join}]/, ALPHABET_TO_SIMPLE_LEET)
|
59
110
|
end
|
60
111
|
|
61
112
|
def leet?
|
@@ -65,8 +116,8 @@ module Passweird
|
|
65
116
|
# Converts the leet speak string back to normal text
|
66
117
|
#
|
67
118
|
# @return [String] the converted normal text string
|
68
|
-
def
|
69
|
-
given_string.gsub(/[#{
|
119
|
+
def unleet
|
120
|
+
given_string.upcase.gsub(/[#{LEET_TO_ALPHABET.keys.join}]/, LEET_TO_ALPHABET)
|
70
121
|
end
|
71
122
|
end
|
72
123
|
end
|
data/lib/passweird/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: passweird
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rupert Señga
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
11
|
+
date: 2025-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|