Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<string.h>
- #include<unistd.h>
- #include<termios.h>
- using namespace std;
- int getch() {
- struct termios oldt, newt;
- int ch;
- tcgetattr(STDIN_FILENO, &oldt);
- newt = oldt;
- newt.c_lflag &= ~(ICANON | ECHO);
- tcsetattr(STDIN_FILENO, TCSANOW, &newt);
- ch = getchar();
- tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
- return ch;
- }
- bool authUser();
- class user{
- char uid[8];
- char pwd[8];
- int level;
- public:
- void initUser(){
- cout<<"\nUsername(7ch max): ";
- cin.getline(uid, 7);
- cout<<"Password(7ch max): ";
- cin.getline(pwd, 7);
- level = 0;
- }
- int authenticate(char *u, char *p){
- if((!strcmp(u, uid)) && (!strcmp(p, pwd)))
- return 1;
- else if(!strcmp(u, uid))
- return 0;
- else
- return -1;
- }
- void _debug(){
- cout<<uid<<"|"<<pwd<<"|"<<level;
- }
- char* getData(int f){
- if(f)
- return uid;
- return pwd;
- }
- int getLevel(){
- return level;
- }
- }CURRENT;
- void addUser(){
- cout<<"\n==========================================================================="
- <<"\n CTC UserDB V1.0";
- user newUser, t;
- newUser.initUser();
- fstream userdb;
- userdb.open("users.ctc", ios::binary|ios::in);
- while(!userdb.eof()){
- userdb.read((char*)&t, sizeof(t));
- if(!strcmp(newUser.getData(1), t.getData(1))){
- cout<<"\nUser already exist, please redo\n";
- userdb.close();
- addUser();
- }
- }
- userdb.close();
- userdb.open("users.ctc", ios::binary|ios::out|ios::app);
- userdb.write((char*)&newUser, sizeof(newUser));
- cout<<"\n User Successfully created";
- userdb.close();
- authUser();
- }
- bool authUser(){
- char u[8],p[8],x;
- int i=0;
- cout<<"\n==========================================================================="
- <<"\n CTC UserAuth V1.1a";
- cout<<"\nUSERNAME : ";cin.getline(u, 7);
- cout<<"PASSWORD : ";
- do{
- x = getch();
- p[i] = x;
- if(x == '\n'){
- p[i]='\0';
- break;
- }
- cout<<"*";
- i++;
- }while(i<8);
- user t;
- fstream userdb;
- userdb.open("users.ctc", ios::binary|ios::in);
- while(!userdb.eof()){
- userdb.read((char*)&t, sizeof(t));
- if(t.authenticate(u, p) == 1){
- CURRENT = t;
- cout<<"\n Logged in successfully as "<<CURRENT.getData(1);
- userdb.close();
- return true;
- }
- else if(t.authenticate(u, p) == 0){
- cout<<"\nWrong password, please login again.";
- userdb.close();
- return authUser();
- }
- }
- cout<<"\nInvalid login data, please login again";
- return authUser();
- }
- int main(){
- char ch;
- cout<<"8\"\"\"\"8 \"\"8\"\" 8\"\"\"\"8\n8 \" eeeee eeeee eeee e e 8 e e eeee 8 \" eeeee eeeee eeee\n8e 8 8 8 8 8 8 8 8 8e 8 8 8 8e 8 88 8 8 8\n88 8eee8e 8eee8 8e 8eee8e 88 8eee8 8eee 88 8 8 8e 8 8eee\n88 e 88 8 88 8 88 88 8 88 88 8 88 88 e 8 8 88 8 88\n88eee8 88 8 88 8 88e8 88 8 88 88 8 88ee 88eee8 8eee8 88ee8 88ee\n";
- cout<<"\n==========================================================================="
- <<"\n Crack The Code V0.1b"
- <<"\n1)Login\n2)Create"
- <<"\n$ ";
- cin>>ch;
- cin.ignore();
- if(ch == '1')
- authUser();
- else
- addUser();
- cout<<"\n==========================================================================="
- <<"\nHello "<<CURRENT.getData(1)<<", you are currently on Level "<<CURRENT.getLevel()<<".\nContinue playing now? (y)es or (n)o";
- }
Add Comment
Please, Sign In to add comment