Sha256: fa1f4d8985c0627a1ee6ddc08250c45b49e86b92499030dae6b4641052873419

Contents?: true

Size: 620 Bytes

Versions: 3

Compression:

Stored size: 620 Bytes

Contents

module GoGamification
  module Checksum
    # Generate a checksum from the given values.
    #
    # values - An Array of values.
    #
    # Returns a String.
    def self.generate values
      Digest::MD5.hexdigest "#{secret_key}#{values.join}"
    end

    # Verify a given checksum against the given values.
    #
    # checksum - A String describing a checksum.
    # values   - An Array of values.
    #
    # Returns a boolean.
    def self.verify checksum, values
      checksum == generate(values)
    end

    private

    def self.secret_key
      Rails.application.secrets[:secret_key_base]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
go_gamification-0.0.7 lib/go_gamification/checksum.rb
go_gamification-0.0.6 lib/go_gamification/checksum.rb
go_gamification-0.0.4 lib/go_gamification/checksum.rb