passlock 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/passlock/class.rb +29 -0
- data/lib/passlock/version.rb +4 -0
- data/lib/passlock.rb +118 -0
- metadata +88 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 2e11f2a118651e5608050f74ee7cee5c1075dafc
         | 
| 4 | 
            +
              data.tar.gz: 19279092c52b4c7178125235f06dbb5f72020021
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: ed12fbc7a5df0f35a5a39bb80eb7a821d5432cccc26d194f47aab57665f18faf62eedfd01a89c0e041e39fec3fbc542895dbd4e93c48df6a55f74f0c986c7cc5
         | 
| 7 | 
            +
              data.tar.gz: b5270547d1090f42a291c57208870ad5d7097cf126a12a459fcefb3c8b2dbb1f714e4abad96147aa3c2fdf1621516faadff8690fc37f83f311ded130e9ff7634
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            require 'base64'
         | 
| 2 | 
            +
            require 'digest/sha1'
         | 
| 3 | 
            +
            require 'digest/sha2'
         | 
| 4 | 
            +
            require 'hmac-sha1'
         | 
| 5 | 
            +
            class String
         | 
| 6 | 
            +
                def to_base
         | 
| 7 | 
            +
                    Base64.encode64 self
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def to_sha1
         | 
| 11 | 
            +
                    Digest::SHA1.hexdigest self
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def to_sha256
         | 
| 15 | 
            +
                    Digest::SHA256.new().update(self).to_s
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def to_sha384
         | 
| 19 | 
            +
                    Digest::SHA384.new().update(self).to_s
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def to_sha512
         | 
| 23 | 
            +
                    Digest::SHA512.new().update(self).to_s
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def to_basehash
         | 
| 27 | 
            +
                    Base64.encode64((HMAC::SHA1.new(self) << 'base').digest).strip
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
            end
         | 
    
        data/lib/passlock.rb
    ADDED
    
    | @@ -0,0 +1,118 @@ | |
| 1 | 
            +
            require 'passlock/class'
         | 
| 2 | 
            +
            require 'passlock/version'
         | 
| 3 | 
            +
            require 'base64'
         | 
| 4 | 
            +
            require 'digest/sha1'
         | 
| 5 | 
            +
            require 'digest/sha2'
         | 
| 6 | 
            +
            require 'hmac-sha1'
         | 
| 7 | 
            +
            require 'securerandom'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            module PassLock
         | 
| 10 | 
            +
                @opts = {
         | 
| 11 | 
            +
                    'number' => '1234567890',
         | 
| 12 | 
            +
                    'upletter' => 'qwertyuiopasdfghjklzxcvbnm'.upcase,
         | 
| 13 | 
            +
                    'downletter' => 'qwertyuiopasdfghjklzxcvbnm',
         | 
| 14 | 
            +
                    'symbols' => %q{`~!@#$%^&*()_+-=[]{}\|;':",.<>/?}
         | 
| 15 | 
            +
                }
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                # A randomly generated passord.
         | 
| 18 | 
            +
                # @param options [Array] Options for the password given in strings. Available strings `number` `upletter` `downletter` `symbol`
         | 
| 19 | 
            +
                # @param length [Integer] How long the password will be
         | 
| 20 | 
            +
                # @return [String] Returns the Base64-encoded version of the password.
         | 
| 21 | 
            +
                def self.cpass(options, length)
         | 
| 22 | 
            +
                    options = options != Array || options.empty? ? options : ['number', 'upletter', 'downletter', 'symbol']
         | 
| 23 | 
            +
                    length = length.is_a(Integer) && length > 0 ? length : 10
         | 
| 24 | 
            +
                    chars = []
         | 
| 25 | 
            +
                    result = ""
         | 
| 26 | 
            +
                    options.each do |flag|
         | 
| 27 | 
            +
                        if not @opts[flag].nil?
         | 
| 28 | 
            +
                            chars.concat(@opts[flag].scan(/./))
         | 
| 29 | 
            +
                        end
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
                    length.to_i.times do
         | 
| 32 | 
            +
                        result += chars.sample
         | 
| 33 | 
            +
                    end
         | 
| 34 | 
            +
                    result
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                # Creates a UUID.
         | 
| 38 | 
            +
                # @return [String] The UUID
         | 
| 39 | 
            +
                def self.uuid
         | 
| 40 | 
            +
                    SecureRandom.uuid
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                # Encodes password in Base64.
         | 
| 44 | 
            +
                # @param pass [String] The password to be encoded
         | 
| 45 | 
            +
                # @param layers [Fixnum] The amount of layering
         | 
| 46 | 
            +
                # @return [String] Returns the Base64-encoded version of the password
         | 
| 47 | 
            +
                def self.base64(pass, layers: 1)
         | 
| 48 | 
            +
                    layers.times do
         | 
| 49 | 
            +
                        pass = Base64.encode64 pass
         | 
| 50 | 
            +
                    end
         | 
| 51 | 
            +
                    pass
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                # Creats a SHA1 hash.
         | 
| 55 | 
            +
                # @param pass [String] The password to be encoded
         | 
| 56 | 
            +
                # @param layers [Fixnum] The amount of layering
         | 
| 57 | 
            +
                # @return [String] The SHA1 hash
         | 
| 58 | 
            +
                def self.sha1(pass, layers: 1)
         | 
| 59 | 
            +
                    layers.times do
         | 
| 60 | 
            +
                        pass = Digest::SHA1.hexdigest pass
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
                    pass
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                # Creats a SHA256 hash.
         | 
| 66 | 
            +
                # @param pass [String] The password to be encoded
         | 
| 67 | 
            +
                # @param layers [Fixnum] The amount of layering
         | 
| 68 | 
            +
                # @return [String] The SHA256 hash
         | 
| 69 | 
            +
                def self.sha256(pass, layers: 1)
         | 
| 70 | 
            +
                    layers.times do
         | 
| 71 | 
            +
                        pass = Digest::SHA256.new().update(pass).to_s
         | 
| 72 | 
            +
                    end
         | 
| 73 | 
            +
                    pass
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                # Creats a SHA384 hash.
         | 
| 77 | 
            +
                # @param pass [String] The password to be encoded
         | 
| 78 | 
            +
                # @param layers [Fixnum] The amount of layering
         | 
| 79 | 
            +
                # @return [String] The SHA384 hash
         | 
| 80 | 
            +
                def self.sha384(pass, layers: 1)
         | 
| 81 | 
            +
                    layers.times do
         | 
| 82 | 
            +
                        pass = Digest::SHA384.new().update(pass).to_s
         | 
| 83 | 
            +
                    end
         | 
| 84 | 
            +
                    pass
         | 
| 85 | 
            +
                end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                # Creats a SHA512 hash.
         | 
| 88 | 
            +
                # @param pass [String] The password to be encoded
         | 
| 89 | 
            +
                # @param layers [Fixnum] The amount of layering
         | 
| 90 | 
            +
                # @return [String] The SHA512 hash
         | 
| 91 | 
            +
                def self.sha512(pass, layers: 1)
         | 
| 92 | 
            +
                    layers.times do
         | 
| 93 | 
            +
                        pass = Digest::SHA512.new().update(pass).to_s
         | 
| 94 | 
            +
                    end
         | 
| 95 | 
            +
                    pass
         | 
| 96 | 
            +
                end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                # Encodes password in Base64 encoded hash.
         | 
| 99 | 
            +
                # @param pass [String] The password to be encoded
         | 
| 100 | 
            +
                # @param layers [Fixnum] The amount of layering
         | 
| 101 | 
            +
                # @return [String] The Base64-encoded hash
         | 
| 102 | 
            +
                def self.base64hash(pass, layers: 1)
         | 
| 103 | 
            +
                    layers.times do
         | 
| 104 | 
            +
                        pass = Base64.encode64((HMAC::SHA1.new(pass) << 'base').digest).strip
         | 
| 105 | 
            +
                    end
         | 
| 106 | 
            +
                    pass
         | 
| 107 | 
            +
                end
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                class Decode
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                    # Decodes password in Base64.
         | 
| 112 | 
            +
                    # @param base [String] The Base64-encoded of the original password
         | 
| 113 | 
            +
                    # @return [String] Returns the decoded password
         | 
| 114 | 
            +
                    def self.base64(base)
         | 
| 115 | 
            +
                        Base64.decode64 base
         | 
| 116 | 
            +
                    end
         | 
| 117 | 
            +
                end
         | 
| 118 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,88 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: passlock
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Snazzah
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2016-06-18 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: bundler
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - ">="
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '0'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - ">="
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: pry
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ">="
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ">="
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: ruby-hmac
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :runtime
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            description: A gem that makes ideal passwords in various ways.
         | 
| 56 | 
            +
            email: botboybeta@yahoo.com
         | 
| 57 | 
            +
            executables: []
         | 
| 58 | 
            +
            extensions: []
         | 
| 59 | 
            +
            extra_rdoc_files: []
         | 
| 60 | 
            +
            files:
         | 
| 61 | 
            +
            - lib/passlock.rb
         | 
| 62 | 
            +
            - lib/passlock/class.rb
         | 
| 63 | 
            +
            - lib/passlock/version.rb
         | 
| 64 | 
            +
            homepage: http://snazzypine25.github.io
         | 
| 65 | 
            +
            licenses:
         | 
| 66 | 
            +
            - MIT
         | 
| 67 | 
            +
            metadata: {}
         | 
| 68 | 
            +
            post_install_message: 
         | 
| 69 | 
            +
            rdoc_options: []
         | 
| 70 | 
            +
            require_paths:
         | 
| 71 | 
            +
            - lib
         | 
| 72 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 73 | 
            +
              requirements:
         | 
| 74 | 
            +
              - - ">="
         | 
| 75 | 
            +
                - !ruby/object:Gem::Version
         | 
| 76 | 
            +
                  version: '0'
         | 
| 77 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 78 | 
            +
              requirements:
         | 
| 79 | 
            +
              - - ">="
         | 
| 80 | 
            +
                - !ruby/object:Gem::Version
         | 
| 81 | 
            +
                  version: '0'
         | 
| 82 | 
            +
            requirements: []
         | 
| 83 | 
            +
            rubyforge_project: 
         | 
| 84 | 
            +
            rubygems_version: 2.5.1
         | 
| 85 | 
            +
            signing_key: 
         | 
| 86 | 
            +
            specification_version: 4
         | 
| 87 | 
            +
            summary: A gem that makes ideal passwords in various ways.
         | 
| 88 | 
            +
            test_files: []
         |