0.0
No release in over a year
A token generator with an identifiable prefix and a 32-bit checksum suffix.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

 Project Readme

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")
# "xoxo_3Q8oOwJyFzbuUaYIv2CPyu12K6gjmy2O8PIK"

# highly recommended that you introduce a secret as well
token_two = TokenChecksum.generate("xoxo", secret: "foo")
# "xoxo_4ftnAniunUKy6x0V75sMVg1VerpU2y1FoRT2"

# can also validate checksums
TokenChecksum.valid?(token_one)
# true

TokenChecksum.valid?(token_two, secret: "foo")
# true

TokenChecksum.valid?(token_two, secret: "bleh")
# FALSE

# can also validate on prefix
TokenChecksum.valid?(token_one)
# true

TokenChecksum.valid?(token_one, valid_prefixes: ["xoxo"])
# true

TokenChecksum.valid?(token_one, valid_prefixes: ["abcd"])
# FALSE

License

The gem is available as open source under the terms of the MIT License.