Advertisement
Guest User

main

a guest
Sep 21st, 2011
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <windows.h>
  5. #include <dos.h>
  6. #include <iostream>
  7. #include <fstream>
  8. #include <ostream>
  9. #include <string>
  10. #include <time.h>
  11. #include "defines.h"
  12. using namespace std;
  13.  
  14. int menuprincipale()
  15. {
  16.     system("cls");
  17.     printf("\n main menu.");
  18.     getchar();
  19.     return 0;
  20. }
  21.  
  22. void LoginScreen()
  23. {
  24.     char logpass[MAX_PASS_SIZE+1];
  25.     char logname[MAX_NAME_SIZE+1];
  26.     char * name_confirm;
  27.     char * pass_confirm;
  28.     FILE * nFile;
  29.     FILE * pFile;
  30.     long nSize;
  31.     long pSize;
  32.     size_t result;
  33.     size_t result2;
  34.     nFile = fopen(LUSER_FILE, "r+" ); // CONFERMA NOME
  35.     if (nFile == NULL) { cout << "LUSER_FILE error. (7)" << endl; exit(7); }
  36.     fseek(nFile, 0, SEEK_END);
  37.     nSize = ftell(nFile);
  38.     rewind(nFile);
  39.     name_confirm = (char*) malloc (sizeof(char) *nSize);
  40.     if (name_confirm == NULL) { cout << "memory error. (8)" << endl; exit(8); }
  41.     result = fread(name_confirm,1,nSize,nFile);
  42.     if (result != nSize) { cout << "reading error. (9)" << endl; exit(9); }
  43.     fclose(nFile);
  44.     pFile = fopen(LPASS_FILE, "r+" ); // CONFERMA PASSWORD
  45.     if (pFile == NULL) { cout << "LPASS_FILE error(4)." << endl; exit(4); }
  46.     fseek(pFile, 0, SEEK_END);
  47.     pSize = ftell(pFile);
  48.     rewind(pFile);
  49.     pass_confirm = (char*) malloc (sizeof(char) *pSize);
  50.     if (pass_confirm == NULL) { cout << "memory error(5). (2nd)" << endl; exit(5); }
  51.     result2 = fread(pass_confirm, 1, pSize, pFile);
  52.     if (result != pSize) { cout << "reading error(6)." << endl; exit(6); }
  53.     fclose(pFile);
  54.     system("cls"); // OUTPUT
  55.     cout<<endl;
  56.     printf("                           Please Login                              ");
  57.     cout<<endl;
  58.     cout<<endl;
  59.     printf("      Username: ");
  60.     scanf("%s", &logname);
  61.     cout<<endl;
  62.     printf("      Password: ");
  63.     scanf("%s", &logpass);
  64.     if ((logname == name_confirm) && (logpass == pass_confirm)) //COMPARAZIONE NOME,PASS INSERITI CON NOME,PASS FILE
  65.     {
  66.         cout << endl << "Access Granted.";
  67.         menuprincipale();
  68.     }
  69.     else {
  70.         cout << endl;
  71.         cout << "Access Denied. Incorrect username or password. Shutting down...";
  72.         sleep(3000);
  73.         system("exit");
  74.     }
  75. }
  76.  
  77. void RegisterScreen()
  78. {
  79.     char * username[MAX_NAME_SIZE+1];
  80.     char * password[MAX_PASS_SIZE+1];
  81.     system("cls");
  82.     ofstream n(LUSER_FILE);
  83.     n.open(LUSER_FILE);
  84.     cout<<endl;
  85.     printf("                                 Register Please                                 \n");
  86.     cout<<endl;
  87.     cout<<endl;
  88.     printf("      Username: ");
  89.     scanf("%s",&username);
  90.     n << username;
  91.     n.close();
  92.     ofstream p(LPASS_FILE);
  93.     p.open(LPASS_FILE);
  94.     cout<<endl;
  95.     printf("      Password: ");
  96.     scanf("%s",&password);
  97.     p << password;
  98.     p.close();
  99.     ofstream l(LLOGS_FILE);
  100.     l << 1;
  101.     sleep(500);
  102.     cout<<endl;
  103.     printf(" Registered succesfully.");
  104.     sleep(500);
  105.     menuprincipale();
  106. }
  107.  
  108. float IsRegistered()
  109. {
  110.     char reg_confirm[256];
  111.     /* FILE * llFile;
  112.     long llSize;
  113.     size_t result;
  114.     llFile = fopen (LLOGS_FILE, "r+" );
  115.     if (llFile == NULL) { cout << "reg check error(1)." << endl; exit(1); }
  116.     fseek(llFile, 0, SEEK_END);
  117.     llSize = ftell(llFile);
  118.     rewind(llFile);
  119.     reg_confirm = (char*) malloc (sizeof(char)*llSize);
  120.     if (reg_confirm == NULL) { cout << "reg check memory error(2)." << endl; exit(2); }
  121.     result = fread(reg_confirm, 1, llSize, llFile);
  122.     if (result != llSize) { cout << "reg check reading error(3)." << endl; exit(3); } */
  123.     fstream file_op(LLOGS_FILE, ios::in);
  124.     file_op.getline(reg_confirm, 256);
  125.     file_op.close();
  126.     if (reg_confirm == "0") { RegisterScreen(); }
  127.     else if (reg_confirm == NULL) { cout << "file is null"; }
  128.     else { cout << "error"; exit(99);}
  129.     // fclose(llFile);
  130.    
  131. }
  132.  
  133. void FilesCheck()
  134. {
  135.     if (!fexist(LUSER_FILE)) {
  136.         FILE * uFile;
  137.         uFile = fopen (LUSER_FILE, "w+" );
  138.         fclose(uFile);
  139.         cout << "User File Created.\n";
  140.         sleep(750);
  141.     }
  142.     else {
  143.         cout << "User File Loaded.\n";
  144.         sleep(750);
  145.     }
  146.     if (!fexist(LPASS_FILE)) {
  147.         FILE * pFile;
  148.         pFile = fopen (LPASS_FILE, "w+" );
  149.         fclose(pFile);
  150.         cout << "Password File Created.\n";
  151.         sleep(750);
  152.     }
  153.     else {
  154.         cout << "Password File Loaded.\n";
  155.         sleep(750);
  156.     }
  157.     if (!fexist(LLOGS_FILE)) {
  158.         /* FILE * lFile;
  159.         char * buffer = { "0" };
  160.         lFile = fopen (LLOGS_FILE, "w+" );
  161.         fwrite(buffer, 1, sizeof(buffer), lFile);
  162.         fclose(lFile); */
  163.         fstream file_op(LLOGS_FILE, ios::out);
  164.         file_op << "0";
  165.         file_op.close();
  166.         cout << "Log File Created.\n";
  167.         sleep(750);
  168.     }
  169.     else {
  170.         cout << "Log File Loaded.\n";
  171.         sleep(750);
  172.     }
  173. }
  174.  
  175. void logincheck()
  176. {
  177.     system("cls");
  178.     cout << endl;
  179.     cout << endl;
  180.     cout << " Checking Files..." << endl;
  181.     cout << endl;
  182.     cout << " STATUS: " << endl;
  183.     cout << endl;
  184.     sleep(2000);
  185.     FilesCheck();
  186.     sleep(750);
  187.     cout << endl << " Checking registration..." << endl;
  188.     sleep(750);
  189.     IsRegistered();
  190. }
  191.  
  192. void firstscreen()
  193. {
  194.     int a;
  195.     a = 1;
  196.     system("cls");
  197.     system("color 0a");
  198.     printf("\n");
  199.     printf("                    --------- output ---------                   \n");
  200.     printf("\n");
  201.     while (a<5)
  202.     {
  203.         system("cls");
  204.         printf("\n");
  205.         printf("                    --------- output ---------                   \n");
  206.         printf("\n");
  207.         sleep(500);
  208.         printf("                                output                                  ");
  209.         sleep(500);
  210.         a++;
  211.     }
  212.     logincheck();  
  213. }
  214.  
  215. int main()
  216. {
  217.     firstscreen(); // Schermata iniziale
  218.     return 0;
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement