char authentication(char* login, char* password) {
	char getUserSelect[255];
	char* errorMessage = 0;
	
	if (strlen(login) > MAX_LOGIN_LINGTH && strlen(password) > MAX_PASSWORD_LINGTH) {
		return AUTHENTICATION_ERROR;
	}
	sprintf(getUserSelect, "SELECT password, role, user_id FROM user WHERE login = '******'", login);
    if (dataBase == NULL) {
        if (openDataBase() == SQLITE_OK) {
            return AUTHENTICATION_ERROR;
        }
    }
	if (sqlite3_exec(dataBase, getUserSelect, fillResult, 0, &errorMessage) != SQLITE_OK) {
		fprintf(stderr, "SQL error: %s\n", errorMessage);
		sqlite3_free(errorMessage);
	}

	if (!strcmp(resultPassword, password)) {
		return resultRole;
	}
	return NO_SUCH_USER;
}
Exemple #2
0
MainDataBase::MainDataBase(QString name)
{
    openDataBase(name);
}