To go more indepth i have a program where I want to prompt the user to type their given username and password (Given from me) and make them type it in, if it is correct it will run a check on the hostname to see if the password matches their hostname that they told me. So basicaly make something like this:
cout << "Type in your username: ";
cin >> username;
cout << "Type in your password: ";
cin >> password;
if (username == "Example" && password == "Example") { /* Checks if correct
combination.*/
cout << "Correct combination, running Hostname scan\n";
// Than scan hostname and assign it to this string "hostname"
if (hostname == "Example's Computer") {
cout << "Access granted\n";
system("cls"); // And clear the screan!
}
This is so if I were to sell a program and than give him his Username and Password, and than he gives me his hostname so he cant just give the hack away for free, since he has given me his computers name!
If you want to get the hostname for the local computer on Windows, you can just call gethostname()
, or one of the related winsock functions, depending on your needs.