Scripting Exercise: Credit Card Challenge

As part of the LoadRunner 8.1 Hands-On Lab training, there is an exercise to enhance a VuGen script that books a flight using the Mercury Tours application.

Company “A” wants the script to generate 10 digit credit card numbers instead of supplying them from an external source on every iteration and for an unlimited number of iterations.

How do you make the script generate credit card numbers for every iteration?

As the Mercury Tours application does not check if the credit card numbers conform to a valid format, the answer to this question is just to replace the file-based credit card parameter with a random parameter using a number format of %010lu.

The purpose of Mercury’s training is to cover as much of the basic concepts as possible in a short space of time, so they can’t make the exercises too hard; but I don’t like to leave people with the incorrect idea that just because they’ve finished some training they are totally prepared for the level of difficulty they will encounter in the real world.

I have created an exercise where you will need to submit different credit card numbers, but I have made it more difficult as they must be valid credit card numbers.

Start the Credit Card Validation Exercise here.

Credit cards (photo from Wikmedia Commons, by Lotus Head)

Some quick notes:

  • The exercise is quite simple. If you work intelligently (and do some research), it should not take long.
  • Make sure that you really do generate the cards at runtime. Finding 60 different card numbers on the web, trying card numbers at random until you find ones that work, and generating card numbers outside of LoadRunner all miss the point of the scripting exercise.
  • Do not run load against my server. Don’t run more than 1 virtual user at a time and be kind with your thinktime and pacing settings.
  • Please report functional defects to me via email: stuart at myloadtest dot com
  • Once some people have emailed me their solution scripts, I will post some comments about my preferred solution.

Here are some credit card numbers to get you started:

  • 30100000000002 (Diners)
  • 30100000000010 (Diners)
  • 4000000000000002 (VISA)
  • 4000000000000010 (VISA)
  • 5400000000000005 (MasterCard)
  • 5400000000000013 (MasterCard)
  • 340000000000009 (American Express)
  • 340000000000017 (American Express)

Good luck!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

3 Responses to “Scripting Exercise: Credit Card Challenge”

  1. Stuart Moncrieff Says:

    http://www.codeproject.com/isapi/isapi_extensions.asp

  2. jerry Says:

    Is it possible to get your solution also?
    Thanks.

    You got great website, which I learned from!

  3. Ramanjaneyulu Narra Says:

    I have written a function that generates a random credit card number first, then verifies for the fuhn algorithm. If everything is fine, then the random number is written to the log. I generated 16 random numbers and then merged them in to a char array. Here is my code. I have validated the values generated by my script. Its working. One thing I missed in this function is that for Diners Club, I didn’t consider the series 36 and 38. I considered only 300 -305 series. As I am generating the random numbers atlest 11 times to generate the credit card number, it should be unique 99.99% of times.

    Here is my code:

    /**************************************************************************************************************/
    int a,i,j,cardcount=0;
    int cardprefix,forlength,temp;
    int cardtype,arraysize;
    int arrayB[16],sum=0,multiple;
    char creditcardNum[64];
    char tmp[16];
    strcpy(creditcardNum,”");

    // End of Variable Declaration

    j=0;
    do
    {

    switch(j)
    {
    case 0: arraysize = 16;
    cardtype = 1;
    forlength = 14;
    //lr_output_message (”The for lenght is: %d”,forlength);
    break;
    case 1: arraysize = 16;
    cardtype = 2;
    forlength = 15;
    //lr_output_message (”The for lenght is: %d”,forlength);
    break;
    case 2: arraysize = 15;
    cardtype = 3;
    forlength = 13;
    //lr_output_message (”The for lenght is: %d”,forlength);
    break;
    case 3: arraysize = 14;
    cardtype = 4;
    forlength = 12;
    //lr_output_message (”The for lenght is: %d”,forlength);
    break;
    };

    do
    {
    do
    {
    for(i=0;i<forlength;i++)
    {
    a= rand()%10;
    arrayB[i] = a;
    }
    if(cardtype==1)
    {
    arrayB[14] = rand()%5 + 1;
    arrayB[15] = 5;
    }
    if(cardtype==2)
    {
    arrayB[15] = 4;
    }
    if(cardtype==3)
    {
    if(rand()%2==0)
    {
    arrayB[13] = 4;
    }
    else
    {
    arrayB[13]=7;
    }
    arrayB[14] = 3;
    arrayB[15]=0;
    }

    if(cardtype==4)
    {
    arrayB[11] = rand()%6;
    arrayB[12] = 0;
    arrayB[13] = 3;
    arrayB[14]=0;
    arrayB[15]=0;
    }

    for(i=0;i9)
    {
    temp=temp-9;
    }
    }
    else
    {
    temp=arrayB[i];
    }
    sum = sum + temp;

    }
    if(sum%10==0)
    {
    cardcount++;
    //lr_output_message(”The random number accepted is: %lu”,creditcardNum);

    //lr_output_message (”The number is accepted”);
    strcpy(creditcardNum,”");
    for(i=15;i>=0;i–)
    {
    itoa(arrayB[i],tmp,10);
    strcat(creditcardNum,tmp);
    }
    lr_output_message (”%s”,creditcardNum);

    sum=0;
    }
    else
    {
    //lr_output_message (”The number is not accepted”);
    sum=0;
    }
    }while(sum%10!=0); //internal do while
    }while(cardcount <15); //second do while
    cardcount =0;
    j++;

    }while(j<4);//last loop
    /**************************************************************************************************************************/

    Please let me know if you need any further details in this regard.

    Thanks and Regards,
    Ramanjaneyulu Narra.

Leave a Reply