Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <windows.h>
- #include <dos.h>
- #include <iostream>
- #include <fstream>
- #include <ostream>
- #include <string>
- #include <time.h>
- #include "defines.h"
- using namespace std;
- int menuprincipale()
- {
- system("cls");
- printf("\n main menu.");
- getchar();
- return 0;
- }
- void LoginScreen()
- {
- char logpass[MAX_PASS_SIZE+1];
- char logname[MAX_NAME_SIZE+1];
- char * name_confirm;
- char * pass_confirm;
- FILE * nFile;
- FILE * pFile;
- long nSize;
- long pSize;
- size_t result;
- size_t result2;
- nFile = fopen(LUSER_FILE, "r+" ); // CONFERMA NOME
- if (nFile == NULL) { cout << "LUSER_FILE error. (7)" << endl; exit(7); }
- fseek(nFile, 0, SEEK_END);
- nSize = ftell(nFile);
- rewind(nFile);
- name_confirm = (char*) malloc (sizeof(char) *nSize);
- if (name_confirm == NULL) { cout << "memory error. (8)" << endl; exit(8); }
- result = fread(name_confirm,1,nSize,nFile);
- if (result != nSize) { cout << "reading error. (9)" << endl; exit(9); }
- fclose(nFile);
- pFile = fopen(LPASS_FILE, "r+" ); // CONFERMA PASSWORD
- if (pFile == NULL) { cout << "LPASS_FILE error(4)." << endl; exit(4); }
- fseek(pFile, 0, SEEK_END);
- pSize = ftell(pFile);
- rewind(pFile);
- pass_confirm = (char*) malloc (sizeof(char) *pSize);
- if (pass_confirm == NULL) { cout << "memory error(5). (2nd)" << endl; exit(5); }
- result2 = fread(pass_confirm, 1, pSize, pFile);
- if (result != pSize) { cout << "reading error(6)." << endl; exit(6); }
- fclose(pFile);
- system("cls"); // OUTPUT
- cout<<endl;
- printf(" Please Login ");
- cout<<endl;
- cout<<endl;
- printf(" Username: ");
- scanf("%s", &logname);
- cout<<endl;
- printf(" Password: ");
- scanf("%s", &logpass);
- if ((logname == name_confirm) && (logpass == pass_confirm)) //COMPARAZIONE NOME,PASS INSERITI CON NOME,PASS FILE
- {
- cout << endl << "Access Granted.";
- menuprincipale();
- }
- else {
- cout << endl;
- cout << "Access Denied. Incorrect username or password. Shutting down...";
- sleep(3000);
- system("exit");
- }
- }
- void RegisterScreen()
- {
- char * username[MAX_NAME_SIZE+1];
- char * password[MAX_PASS_SIZE+1];
- system("cls");
- ofstream n(LUSER_FILE);
- n.open(LUSER_FILE);
- cout<<endl;
- printf(" Register Please \n");
- cout<<endl;
- cout<<endl;
- printf(" Username: ");
- scanf("%s",&username);
- n << username;
- n.close();
- ofstream p(LPASS_FILE);
- p.open(LPASS_FILE);
- cout<<endl;
- printf(" Password: ");
- scanf("%s",&password);
- p << password;
- p.close();
- ofstream l(LLOGS_FILE);
- l << 1;
- sleep(500);
- cout<<endl;
- printf(" Registered succesfully.");
- sleep(500);
- menuprincipale();
- }
- float IsRegistered()
- {
- char reg_confirm[256];
- /* FILE * llFile;
- long llSize;
- size_t result;
- llFile = fopen (LLOGS_FILE, "r+" );
- if (llFile == NULL) { cout << "reg check error(1)." << endl; exit(1); }
- fseek(llFile, 0, SEEK_END);
- llSize = ftell(llFile);
- rewind(llFile);
- reg_confirm = (char*) malloc (sizeof(char)*llSize);
- if (reg_confirm == NULL) { cout << "reg check memory error(2)." << endl; exit(2); }
- result = fread(reg_confirm, 1, llSize, llFile);
- if (result != llSize) { cout << "reg check reading error(3)." << endl; exit(3); } */
- fstream file_op(LLOGS_FILE, ios::in);
- file_op.getline(reg_confirm, 256);
- file_op.close();
- if (reg_confirm == "0") { RegisterScreen(); }
- else if (reg_confirm == NULL) { cout << "file is null"; }
- else { cout << "error"; exit(99);}
- // fclose(llFile);
- }
- void FilesCheck()
- {
- if (!fexist(LUSER_FILE)) {
- FILE * uFile;
- uFile = fopen (LUSER_FILE, "w+" );
- fclose(uFile);
- cout << "User File Created.\n";
- sleep(750);
- }
- else {
- cout << "User File Loaded.\n";
- sleep(750);
- }
- if (!fexist(LPASS_FILE)) {
- FILE * pFile;
- pFile = fopen (LPASS_FILE, "w+" );
- fclose(pFile);
- cout << "Password File Created.\n";
- sleep(750);
- }
- else {
- cout << "Password File Loaded.\n";
- sleep(750);
- }
- if (!fexist(LLOGS_FILE)) {
- /* FILE * lFile;
- char * buffer = { "0" };
- lFile = fopen (LLOGS_FILE, "w+" );
- fwrite(buffer, 1, sizeof(buffer), lFile);
- fclose(lFile); */
- fstream file_op(LLOGS_FILE, ios::out);
- file_op << "0";
- file_op.close();
- cout << "Log File Created.\n";
- sleep(750);
- }
- else {
- cout << "Log File Loaded.\n";
- sleep(750);
- }
- }
- void logincheck()
- {
- system("cls");
- cout << endl;
- cout << endl;
- cout << " Checking Files..." << endl;
- cout << endl;
- cout << " STATUS: " << endl;
- cout << endl;
- sleep(2000);
- FilesCheck();
- sleep(750);
- cout << endl << " Checking registration..." << endl;
- sleep(750);
- IsRegistered();
- }
- void firstscreen()
- {
- int a;
- a = 1;
- system("cls");
- system("color 0a");
- printf("\n");
- printf(" --------- output --------- \n");
- printf("\n");
- while (a<5)
- {
- system("cls");
- printf("\n");
- printf(" --------- output --------- \n");
- printf("\n");
- sleep(500);
- printf(" output ");
- sleep(500);
- a++;
- }
- logincheck();
- }
- int main()
- {
- firstscreen(); // Schermata iniziale
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement