Skip to content

Instantly share code, notes, and snippets.

@vasinov
Created February 7, 2014 00:03
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vasinov/8855052 to your computer and use it in GitHub Desktop.
Save vasinov/8855052 to your computer and use it in GitHub Desktop.
generate_authentication_token
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