I am developing a set of tools in Java for validating and working with credit cards. So far I have support for:
LUHN validation.
Date validation (simple expiration).
Card code length validation (CVV, CVC, CID) based on the brand (Visa, MasterCard, etc).
Credit card number length validation (based on the brand).
BIN/IIN validation (against a database of valid numbers).
Hiding the digits (425010 * * * * * * 1234)
To make the tool set a bit more complete, I would like to create a credit card random number generator based on the different card brands. This functionality will (hopefully) make my test cases a bit more reliable.
Basically, I would like to be able to generate numbers which are:
LUHN valid
Valid based on the brand prefixes
Valid based on the BIN/IIN prefix numbers
For BIN/IIN valid card numbers, I am thinking of looking up a random BIN/IIN number from the database (based on the brand of course) and then appending the remaining digits using Random
. Obviously, that would not be valid most of the time and I will have to increment one of the digits until it passes the LUHN validation.
I can't seem to be able to think of a better way. Perhaps someone could suggest something a little smarter...?
Looking forward to your suggestions! Thanks in advance! :)