Skip to content

Instantly share code, notes, and snippets.

@tensiondriven
Created June 15, 2012 00:30
Show Gist options
  • Save tensiondriven/2933858 to your computer and use it in GitHub Desktop.
Save tensiondriven/2933858 to your computer and use it in GitHub Desktop.
Email id token encode/decode method
def self.get_guid record_id
str = record_id.to_s(36)
hash = (Digest::SHA1.hexdigest "SALTY#{record_id}HASH")[0..3].downcase
"[#{hash}#{str}]"
end
def self.get_id_for_guid guid
old_hash = guid[0..3]
record_id = guid[4..-1].to_i(36)
hash = (Digest::SHA1.hexdigest "SALTY#{record_id}HASH")[0..3].downcase
if hash == old_hash
record_id
else
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment