Reputation: 3164
I have a process flow where I send a user a link via email with a generated token.
I'm currently generating the token like this:
before_create :generate_token
protected
def generate_token
self.token = loop do
random_token = SecureRandom.urlsafe_base64(nil, false)
break random_token unless ModelName.exists?(token: random_token)
end
end
The user can access the record by going to
mysite.com/records/:token
How can I accomplish the same task with either a hashed or encrypted token? I want to make this link more secure.
Upvotes: 0
Views: 201
Reputation: 2543
Maybe you are looking for ActiveSupport::MessageVerifier.
MessageVerifier makes it easy to generate and verify messages which are signed to prevent tampering.
How Does MessageVerifier Work?
Upvotes: 2