Add has_secure_token to Active Record

I take the audacity of include has_scure_token to Active Model since the implementation is using methods that are implemented in most of popular ORMs or ODMs in ruby, like `exists?`and `save`, is just as suggestion and for sure I'm open to move it to Active Record anyway :smile:. Is still missing documentation but I'd like to hear first opinions about the implementation/code

**Usage**

```ruby
class User < ActiveRecord::Base
  has_secure_token :token1, :token2, key_length: 30
end

user = User.new
user.save
user.token1 # => "973acd04bc627d6a0e31200b74e2236"
user.token2 # => "e2426a93718d1817a43abbaa8508223"
user.regenerate_token1! # => true
user.regenerate_token2! # => true
```

ref #16879

cc @dhh 
Ah, I see. So even less chance of a collision. Gotcha. Sounds good to me :+1:. Could happen in a separate PR though.

On Dec 29, 2014, at 15:13, Matthew Draper <notifications@github.com> wrote:

> In activerecord/lib/active_record/secure_token.rb:
> 
> > +      #   end
> > +      #
> > +      #   user = User.new
> > +      #   user.save
> > +      #   user.token # => "44539a6a59835a4ee9d7b112"
> > +      #   user.regenerate_token # => true
> > +      def has_secure_token(attribute = :token)
> > +        # Load securerandom only when has_secure_key is used.
> > +        require 'securerandom'
> > +        define_method("regenerate_#{attribute}") { update! attribute => self.class.generate_unique_secure_token(attribute) }
> > +        before_create { self.send("#{attribute}=", self.class.generate_unique_secure_token(attribute)) }
> > +      end
> > +
> > +      def generate_unique_secure_token(attribute)
> > +        10.times do |i|
> > +          SecureRandom.hex(12).tap do |token|
> 
> For a given length of 24:
> 
> 16 ** 24  # => 79228162514264337593543950336
> 62 ** 24  # => 10408797222153426578715765348940396820955136
> 
> and apart from needing slightly more code to generate it, it's basically free.
> 
> The discussion went a bit into the woods because base62-the-algorithm is complicated, but we don't care: we just want to generate a series of characters using base62-the-charset.
> 
> —
> Reply to this email directly or view it on GitHub.
>