Ok, searched a bit and found a few relevant posts, but they didn't directly address my problem, so here I am... Basically, I'm trying to write a program that will, hopefully, do the following things in sequential order:
1) Accept certain login credentials (user test, password 1234) and auto-login to a website,
2) Download a temporary file (bfh.txt),
3) Search in bfh.txt for string "var sessionID = X", then copy whatever X (X is randomly generated every login session, it's the value I need copied),
4) Set the copied sessionID to a variable () in the program,
5) Create a runnable shortcut on the desktop to program, with the following parameters included "C:\program.exe" +ServHostName "host.com" +webSiteHostName "hostsite.com" +survey 1 +sessionId X (where X is the value of the sessionID var).

I know that's probly a good deal of coding, and I'm not asking for the whole code, but I do want to know how feasible it would be to make a program like this (in C++)... I know how to actually get it to search for the string, but not sure how to get it to actually copy it. As far as remotely DL'ing the bfh.txt and using the login credentials, I'm somewhat confident I can figure that out. The two issues I just need help with are the copying of the sessionID and setting parameters in the shortcut...

I'm still quite new to C++ (altho do have experience in web-based languages, etc), which is why I was asking for help rather than figure it out myself, as I would prefer to have this program complete asap :P

Anyways, below is the code I have at the moment (only the search part, taken from another post on these forums I found; I haven't written the other parts of the program yet), thanks in advance for any help or suggestions you can give me:

#include <iostream>

using namespace std;

      std::ifstream in ( "path_to_desktop\bfh.txt" );
       
      if ( in ) {
      bool found = false;
      std::string search_for = "var sessionID = [RandomKey] ";
      std::string line;
       
      while ( std::getline ( in, line ) ) {
      if ( word.find ( search_word ) != std::string::npos ) {

      found = true;

      break;

      }
      }
       
      //...
      }

About that X extraction:

Find "var sessionId = " then extract RandomKey. The last operation depends on the RandomKey terninator (or the next field delimiter). For example, if RandomKey field terninator is a blank char ' ' it looks like:

const size_t none = std::string::npos;
std::string key, varid("var sessionID = ");
...
size_t pos;
  while (std::getline(in,line)) {
    if ((pos = line.find(varid)) != none) {
        pos += sid.size(); // key start pos
        key = line.substr(pos);
        pos = key.find(' '); // or other terminator
        if (pos != none)
            key = key.substr(0,pos);
        found = true;
        break;
    }
  }

Warning: I didn't debug this code sceleton!

This article has been dead for over six months. Start a new discussion instead.