Created
June 21, 2014 20:07
-
-
Save vito-lbs/bc5459b02bd915cc898a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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