Skip to content

Instantly share code, notes, and snippets.

@vito-lbs
Created June 21, 2014 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vito-lbs/bc5459b02bd915cc898a to your computer and use it in GitHub Desktop.
Save vito-lbs/bc5459b02bd915cc898a to your computer and use it in GitHub Desktop.
def to_token_string
key.chars.zip(@secret.chars).join
end
def self.from_token_string(token_string)
begin
key, secret = token_string.chars.each_slice(2).to_a.transpose.map(&:join)
candidate = self.where(key: key).first
rescue
return nil
end
return nil unless candidate && (candidate.secret == secret)
return candidate
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment