#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <windows.h>
#include <mysql.h>
#include <string.h>
using namespace std;
//FUNCS//
string my_query(string database, string sqlquery,int i);
bool login(string username,string password);
// END FUNCS//
int main(){
string username = "";
string password = "";
cout << "Bitte Benutzername eingeben!\n";
cin >> username;
cout << "Bitte Passwort eingeben!\n";
cin >> password;
if(login(username,password)){
cout << "Eingeloggt!";
}
cout << endl << endl << endl;
}
string my_query(string database, string sqlquery,int i){
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char auswahl;
char antwort_user[100];
string server = "localhost"; //host
string user = "****"; //user
string password = "****"; //passwort
string output = "";
conn = mysql_init(NULL);
/* verbinden zur DB */
if (!mysql_real_connect(conn, server.c_str(),
user.c_str(), password.c_str(), database.c_str(), 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(0);
}
auswahl = (char)0x31;
/* den Inhalt der SQL Query in eine Variable packen*/
//sqlquery = "SELECT * FROM asdf WHERE id = '";
//sqlquery += auswahl;
//sqlquery += "'";
/* die SQL query senden*/
if (mysql_query(conn, sqlquery.c_str())) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(0);
}
res = mysql_use_result(conn);
row = mysql_fetch_row(res);
output = row[i];
/* Speicher freigeben und Verbindung trennen */
mysql_free_result(res);
mysql_close(conn);
return output;
}
bool login(string username,string password){
string query = "";
string db = "gameserver";
string result = "";
query = "SELECT * FROM `login` WHERE `username` = '";
query += username;
query += "' AND `password` = '";
query += password;
query += "' LIMIT 1";
result = my_query(db,query,1);
if(result == username){
return true;
}
else{
return false;
}
}