Skip to content

Instantly share code, notes, and snippets.

@amalrik
Forked from vasinov/gist:8855052
Last active August 29, 2015 14:06
Show Gist options
  • Save amalrik/98f761a69fe6d4205058 to your computer and use it in GitHub Desktop.
Save amalrik/98f761a69fe6d4205058 to your computer and use it in GitHub Desktop.
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