Created
June 15, 2012 00:30
-
-
Save tensiondriven/2933858 to your computer and use it in GitHub Desktop.
Email id token encode/decode method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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