Created
February 7, 2014 00:03
-
-
Save vasinov/8855052 to your computer and use it in GitHub Desktop.
generate_authentication_token
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 generate_authentication_token | |
loop do | |
token = Devise.friendly_token | |
hashed_token = BCrypt::Password.create(token) | |
update_attribute(:token_id, Devise.friendly_token) | |
final_token = "#{token_id}-#{token}" | |
break { token: final_token, hashed_token: hashed_token } unless User.where(authentication_token: hashed_token).first | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment