Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the CouponCode gem #30

Open
ankonym opened this issue Oct 5, 2015 · 0 comments
Open

Replace the CouponCode gem #30

ankonym opened this issue Oct 5, 2015 · 0 comments
Labels

Comments

@ankonym
Copy link

ankonym commented Oct 5, 2015

As per Elijah's comments below:

Remove the coupon gem and instead generate codes with something like this:

Base32.encode(SecureRandom.random_bytes).downcase[0..7]

or

Base64.encode64(SecureRandom.random_bytes).downcase.gsub(/[0oi1+_/]/,'')[0..7]

The first requires the gem base32, but the latter uses only built-in libraries (require 'base64' and require 'securerandom'). This seems better than depending on the coupon gem, especially since we don't use any of the "features" of the coupon gem.

[...]

Base64.encode64(SecureRandom.random_bytes).downcase.gsub(/[0oil1+_/]/,'')[0..7].scan(/..../).join('-')

=> "myk9-qjdb"

We may want the length configurable in the future, but I think anything longer than 8 characters is unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant