KeyValue()

From Hack Wars Wiki

Jump to: navigation, search

Used to obtain data from a login database with the following format in each line:

IP/extraData//username//

The password string is essentially the IP address. This function in particular returns the data in the third spot in the line, i.e. the username.

string keyValue(string filename, string password) {
	string username="";
	string filedata=readFile(filename);
	int p1=indexOf(filedata,password+"/",0);
	if(p1>-1) {
		int p2=indexOf(filedata,"//",p1+1);
		if(p2>-1) {
			int p3=indexOf(filedata,"//",p2+1);
			if(p3>-1) {
				username=substr(filedata,p2+2,p3);
			}
		}
	}
	return username;
}
Personal tools