passweird 0.1.3 → 0.2.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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/passweird/checker.rb +4 -16
- 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: 2e6d59497282552bfae629eb27790ab7052889936ed6cfe37b84ae34c308de1f
         | 
| 4 | 
            +
              data.tar.gz: 79040059aad66e4eb6afaf2e6186b00017aeeed6697658960d7388768dc77f85
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: fdef30ff3536b8fcf72d9cbc2cca93793c2ac4a2802726e3c094d1c6b97ed7d35201dc392d9b4598d329aa31fe9240f84549975ef59cb1818ae95192072d8d20
         | 
| 7 | 
            +
              data.tar.gz: ac5988d41745ce56cb3f071c104e2baa94b5adc0b0044f2188e8b3dd50c85b852af0e309149e66245f5d21d0ca0706b5f8466291c8654339ec6d14e4bfe26182
         | 
    
        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
         | 
| @@ -38,29 +38,17 @@ module Passweird | |
| 38 38 | 
             
                #
         | 
| 39 39 | 
             
                # @return [Array<String>] an array of unique possible terms
         | 
| 40 40 | 
             
                def possible_terms
         | 
| 41 | 
            -
                   | 
| 41 | 
            +
                  ([password] + substrings + unleeted_substrings).uniq
         | 
| 42 42 | 
             
                end
         | 
| 43 43 |  | 
| 44 44 | 
             
                private
         | 
| 45 45 |  | 
| 46 | 
            -
                def  | 
| 47 | 
            -
                  @ | 
| 46 | 
            +
                def substrings
         | 
| 47 | 
            +
                  @substrings ||= Substringer.substrings(password.downcase)
         | 
| 48 48 | 
             
                end
         | 
| 49 49 |  | 
| 50 50 | 
             
                def unleeted_substrings
         | 
| 51 51 | 
             
                  @unleeted_substrings ||= LeetSpeak.unleet_all(substrings)
         | 
| 52 52 | 
             
                end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
                def substrings
         | 
| 55 | 
            -
                  @substrings ||= Substringer.substrings(password)
         | 
| 56 | 
            -
                end
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                def downcased_substrings
         | 
| 59 | 
            -
                  @downcased_substrings ||= substrings.map(&:downcase)
         | 
| 60 | 
            -
                end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                def upcased_substrings
         | 
| 63 | 
            -
                  @upcased_substrings ||= substrings.map(&:upcase)
         | 
| 64 | 
            -
                end
         | 
| 65 53 | 
             
              end
         | 
| 66 54 | 
             
            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.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.1 | 
| 4 | 
            +
              version: 0.2.1
         | 
| 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
         |