Generating unique, hard-to-guess “coupon” codes

前端 未结 8 864
耶瑟儿~
耶瑟儿~ 2020-12-23 10:24

My Rails app needs to generate electronic coupons for users. Each coupon given should have a unique coupon code that can be redeemed on our system.

For example a cou

8条回答
  •  伪装坚强ぢ
    2020-12-23 11:21

    Get an epoch timestamp and base encode it.. as long as you save a record of it somewhere you can compare if it's valid when it's used.

    If you need it to be enterable by hand you can always .string() it down to first 8 or so characters.

提交回复
热议问题