TokenChecksum
Generates a 30 character long random token, with a prefix and a 32-bit checksum in the last 6 digits. Inspired by:
Installation
Install the gem and add to the application's Gemfile by executing:
$ bundle add token_checksum
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install token_checksum
Usage
token_one = TokenChecksum.generate("xoxo")
token_two = TokenChecksum.generate("xoxo", secret: "foo")
TokenChecksum.valid?(token_one)
TokenChecksum.valid?(token_two, secret: "foo")
TokenChecksum.valid?(token_two, secret: "bleh")
TokenChecksum.valid?(token_one)
TokenChecksum.valid?(token_one, valid_prefixes: ["xoxo"])
TokenChecksum.valid?(token_one, valid_prefixes: ["abcd"])
License
The gem is available as open source under the terms of the MIT License.