I need to generate a verification code and send it to a customer, so that the customer can then provide the code later and I validate it. I want to be able to do this without storing the verification codes in a database, i.e., the codes should be self-containted.
How can I generate the code and prevent the customer from just guessing what a valid code is? Obviously, I can't completely rule out a lucky guess, but I want the probability of such an event to be reasonably small, while keeping the code length small. A code may contain digits and letters.
For example, a very basic verification code would be like this: randomly generate the number 1122
. Now, compute the verification code 11226
( 1122
and append its checksum 6=1+1+2+2
). So, if the customer sends back 11226
back I would be able to validate it, but of course this is too easy to tamper with. Is there a method to generate such codes?
EDIT: The problem is that the system which sends the verification code and the system where the verification code is validated are separated, no information is shared between these two systems. There is no way that even the randomly generated number (1122
in the example) is known to the validation system. Let me give you another example: in my country, there is a thing called "Orange Wednesday". You can get 2 movie tickets for the price of one if you have a code received by SMS (you send a SMS and receive a code by SMS if you are Orange customer). However, this code is not tied to anything (phone number or similar): I can give the code to someone else and it is still valid. I would need this kind of verification code.
What you are looking for can be implemented using Message Authentication Codes (MAC):
The key observations to make are:
(message, MAC)
tuple may have.In your scenario, you can use any arbitrary message since your only requirement is to verify that the input you receive from a customer was originally generated by you. You can do this by
012345679xxxxxxx
, or simply take the date encoded as "dd.mm.yyyy hh:mm:ss" for your 'arbitrary message'.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With