Kev Hunter
Kev Hunter

Reputation: 2625

Does anyone know where there is c# code or a dll which can generate sample credit card numbers

For an application we are working on I need to generate sample credit card numbers which pass the Luhn algorithm but which are also unique, so we cannot use the sample credit card numbers.

We need to be able to generate around 300 card numbers at a time, and ideally i would be able to do this when generating my input data.

Many Thanks

Upvotes: 6

Views: 3105

Answers (5)

John Weldon
John Weldon

Reputation: 40759

Do you need the credit card #'s to pass any other tests? i.e. should they look like valid VISA, MasterCard, or AMEX, etc.

If so, you may want a resource like Graham King's otherwise some of the other suggestions here are good.

The latest version of Graham King's generator (including c# code) can be found on GitHub.

Upvotes: 2

Kev Hunter
Kev Hunter

Reputation: 2625

I took the code from Graham Kings site and ported it to c#, also emailing Graham a copy, you can find it here link text

Upvotes: 2

Mike
Mike

Reputation: 5281

If you need a list to test each card, you'll find one here. How to test credit card interactions?

Upvotes: 1

Joey
Joey

Reputation: 354566

From what I see you just need to ensure that when running through the algorithm you get a result of 0 (mod 10). So you can pick any number of random digits (or sequential if you like) and just add one last digit which will ensure that the number is valid.

Upvotes: 3

sisve
sisve

Reputation: 19781

Create random numbers, then calculate the checksum number.

You can find more information at Wikipedia - Luhn, both details about the algorithm and links to different implementations.

Upvotes: 9

Related Questions