+ Reply to Thread
Results 1 to 3 of 3

Thread: Credit Card Verification and Generation Method

  1. #1
    joey
    Guest

    Credit Card Verification and Generation Method

    I'd like to a snippet that does generate and validate credit card number like VISA , MasterCard , AmericanExpress.

    is it possible ?
    Last edited by joey; 10-31-2012 at 03:17 AM.

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    36
    Here is the function to check if the card is valid or not.
    And also i`ll give you the method that generates a Valid VISA numbers.

    So Before we begin , i`d like to menthion that :
    1- You can generate a Valid VISA numbers but you wont be able to use it
    Because it is just generated and it is not assosiated with any bank account and also you do not have
    the Expiration date or CVV which is really important.


    Lets Begin...

    Any Credit Card type verification method ?
    Code:
            private static bool Verify(string number)
            {
                number = number.Replace("-", "");
    
                int[] DELTAS = new int[] { 0, 1, 2, 3, 4, -4, -3, -2, -1, 0 };
                int checksum = 0;
                char[] chars = number.ToCharArray();
                for (int i = chars.Length - 1; i > -1; i--)
                {
                    int j = ((int)chars[i]) - 48;
                    checksum += j;
                    if (((i - chars.Length) % 2) == 0)
                        checksum += DELTAS[j];
                }
    
                return ((checksum % 10) == 0);
            }
    If you used that command :
    Code:
    Console.WriteLine(Verify("123456789123456"));
    Yous should get a True or False Value , since it is bool and True means valid.

    Generate Credit Card Numbers : [VISA Only]
    Code:
            static void Main()
            {
                while (true)
                {
                    Verify(Generate_Numbers());
    				// Added threading to prevent Redundant numbers
                    Thread.Sleep(80);
                }
            }
    
    
            static long LongRandom(long min, long max, Random rand)
            {
                Random random = new Random();
    
                Label001:
                long randomLong = min + (long)(random.NextDouble() * (max - min));
    
    			// 4 is the prefix of VISA numbers.
                if (!randomLong.ToString().StartsWith("4")) goto Label001;
                else
                {
                    return randomLong;
                }
            }
    
            static string Generate_Numbers()
            {
                long r = LongRandom(4000000000000000, 9999999999999999, new Random());
                return r.ToString();
            }
    
            private static bool Verify(string number)
            {
                number = number.Replace("-", "");
    
                int[] DELTAS = new int[] { 0, 1, 2, 3, 4, -4, -3, -2, -1, 0 };
                int checksum = 0;
                char[] chars = number.ToCharArray();
                for (int i = chars.Length - 1; i > -1; i--)
                {
                    int j = ((int)chars[i]) - 48;
                    checksum += j;
                    if (((i - chars.Length) % 2) == 0)
                        checksum += DELTAS[j];
                }
    
                if (((checksum % 10) == 0)) Console.WriteLine(number);
    
                return ((checksum % 10) == 0);
            }
    Hope you enjoyed my Tutorial.
    Last edited by cpro; 10-31-2012 at 03:16 AM.

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    36
    Also that Post here is very helpful >> http://www.beachnet.com/~hstiles/cardtype.html

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts