Tuesday, August 6, 2013

How to encode a string as if a password in Loadrunner?

There are many ways to encode a string in Loadrunner. I already have explained the one using password encoder tool. Below is another way to encode the string but this will convert the plain string to URL format. 

Let’s see how, in this I have defined a function EncodePlainToURL() which accepts a string and encodes it to URL format.

char *EncodePlainToURL(const char *sIn, char *sOut)
 {
                    int i;
                    char cCurChar;
                    char sCurStr[4] = {0};

                     sOut[0] = '\0';
                     for (i = 0; cCurChar = sIn[i]; i++)
                     {
                            if (isdigit(cCurChar) || isalpha(cCurChar))
                             {
                                     sprintf(sCurStr, "%X", cCurChar);

                              }

                             else
                             {
                                                                                                                                                                                      sprintf(sCurStr, "%%%X", cCurChar)
                              }


                               strcat(sOut, sCurStr);
                       }

                    return sOut;
 }

Action()
{

                char sOut[100];
                char sIn[] = "password";
                lr_output_message("the encoded output is %s", EncodePlainToURL(sIn, sOut));
Click here to know more

                return 0;
}


Hope you will try this at home ;) . Thanks for reading :) 

No comments:

Post a Comment