-1

I'm building a system for a small bank for card issuance, what I need is how to make the system generate Card Number sequence (or PAN) based on a specific pattern. For example, First six digits of PAN are the bank BIN: 517070 The next two digits are product code: let's say 30 (Could be any number) the next two digits are branch code: let's say 01 the rest of the digits will be generated randomly (of course the last digit is a check digit)

My questions: is there an algorithm to help me implement these requirements in the system?

This website matches my requirements https://www.elfqrin.com/discard_credit_card_generator.php

Thank you

  • Is PAN just the credit card number? If so, there are many credit card number generators on sites like GitHub, etc. - did any of them match your requirements? – ProgrammingLlama Jul 10 '19 at 08:35
  • Seems like, you need some king of luhn algorithm for that, have a look at this [thread](https://stackoverflow.com/questions/21249670/implementing-luhn-algorithm-using-c-sharp) – Pavel Anikhouski Jul 10 '19 at 08:39
  • @John yes it is just a credit card number. I will look it up, but so far I didn't find anything that matches my requirements. thank you – Mohammed Tellesy Jul 15 '19 at 07:31
  • @PavelAnikhouski, yes the generated number should be validated using luhn algorithm. Thank you I will have a look – Mohammed Tellesy Jul 15 '19 at 07:33

1 Answers1

-1

Use String Format :

          Random rand = new Random();
          string bin = "517070";
          string productCode = "30";
          string branchCode = "01";
          int randNumber = rand.Next(0, int.MaxValue);
          string number = string.Format("{0}{1}{2}{3}", bin, productCode, branchCode, randNumber.ToString("D20"));
jdweng
  • 33,250
  • 2
  • 15
  • 20
  • You need to be *certain* that the random number part is not a duplicate. A simple `rand.next()` is insufficient. Three common ways to ensure uniqueness are 1) keep a list and check for duplicates. 2) shuffle and take the next shuffled number 3) encryption. There a lot of questions discussing the problem on this site. – rossum Jul 10 '19 at 19:23
  • I know. This question is not about a random number. It is about generating a 30 format string that consists of four parts. – jdweng Jul 11 '19 at 01:33
  • @jdweng the number should be a valid credit card number (PAN), and this can be achieved using luhn algorithm and shouldn't be any random number. – Mohammed Tellesy Jul 15 '19 at 07:34
  • I know. I just showed how to format a 30 character string made of 4 parts. You did not specify how to generate the PAN so I just put in a random number to get a 30 character string. You said "the rest of the digits will be generated randomly" – jdweng Jul 15 '19 at 08:49