Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4007CEM/Login and Register.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
112 lines (87 sloc)
2.03 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdio.h> | |
#include <sqlite3.h> | |
#include <string> | |
using namespace std; | |
//create a callback function | |
int callback(void* NotUsed, int argc, char** argv, char** azColName) { | |
// holds the number of results | |
// holds each value | |
// holds each column returned | |
for (int i = 0; i < argc; i++) { | |
//show column name, value, and newline | |
cout << azColName[i] << ": " << argv[i] << endl; | |
} | |
return 0; | |
} | |
class Details { | |
public: | |
string username,password; | |
void DetailsIn() { | |
cout << "Enter Username: "; | |
cin >> username; | |
cout << "Input: " << username << endl; | |
cout << "Enter Password: "; | |
cin >> password; | |
cout << "Input: " << password << endl; | |
}; | |
int MakeDb() { | |
//Pointer | |
sqlite3* db; | |
//Save any error messages | |
char* ErrMsg; | |
int run; | |
string sql; | |
run = sqlite3_open("Details.db", &db); | |
if (run) { | |
cout << "DB Error: " << sqlite3_errmsg(db) << endl; | |
sqlite3_close(db); | |
return 1; | |
} | |
sql = "CREATE TABLE IF NOT EXISTS Details(" \ | |
"ID INT PRIMARY KEY NOT NULL," \ | |
"Username TEXT NOT NULL," \ | |
"Password TEXT NOT NULL);"; | |
run = sqlite3_exec(db, sql.c_str(), callback, 0, &ErrMsg); | |
//Close the SQL Connection | |
sqlite3_close(db); | |
} | |
}; | |
int registration() { | |
//Pointer | |
sqlite3* db; | |
//Save any error messages | |
char* ErrMsg; | |
int run; | |
string sql; | |
run = sqlite3_open("Details.db", &db); | |
if (run) { | |
cout << "DB Error: " << sqlite3_errmsg(db) << endl; | |
sqlite3_close(db); | |
return 1; | |
} | |
sql = "INSERT INTO Details('ID','Username','Password') VALUES (1,'?','?');"; | |
run = sqlite3_exec(db, sql.c_str(), callback, 0, &ErrMsg); | |
//Close the SQL Connection | |
sqlite3_close(db); | |
} | |
int main() { | |
char choose; | |
Details d1; | |
d1.MakeDb(); | |
do { | |
cout << "'R' to Register or 'L' to Login \n"; | |
cin >> choose; | |
switch (choose) | |
{ | |
case 'R': | |
d1.DetailsIn(); | |
registration(); | |
return 0; | |
case 'L': | |
cout << "Login"; | |
} | |
} | |
while (choose != 0); | |
return 0; | |
} |