Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.43 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <cstdlib>
  6. #include <Windows.h>
  7.  
  8. #define MaxPass 25
  9. #define ADDEDLANGUAGES 2
  10.  
  11. using namespace std;
  12.  
  13. int SECURITYCODE = 0000;
  14. bool LOGGED = false;
  15. string PASSWORD, LOGIN;
  16.  
  17. class Language;
  18.  
  19. class Passwords
  20. {
  21. private:
  22.     string website[MaxPass];
  23.     string username[MaxPass];
  24.     string password[MaxPass];
  25.     string email[MaxPass];
  26.     int addedpass = 0;
  27. public:
  28.     void AddPass(Language & lang)
  29.     {
  30.         int code;
  31.         system("cls");
  32.         cout << lang.SchowMessage(5) << endl << endl;
  33.         cin >> code;
  34.         if (code == SECURITYCODE) {
  35.             system("cls");
  36.             cout << "Witaj w kreatorze dodawania Loginu i Hasla do bazy! :D" << endl << endl;
  37.             cout << "Podaj adres strony na ktorej sie zarejestrowales/as:" << endl;
  38.             cin >> website[addedpass];
  39.             system("cls");
  40.             cout << "Witaj w kreatorze dodawania Loginu i Hasla do bazy! :D" << endl << endl;
  41.             cout << "Podaj adres E-Mail do twojego konta na tej stronie:" << endl;
  42.             cin >> email[addedpass];
  43.             system("cls");
  44.             cout << "Witaj w kreatorze dodawania Loginu i Hasla do bazy! :D" << endl << endl;
  45.             cout << "Podaj nazwe uzytkownika twojego konta na tej stronie:" << endl;
  46.             cin >> username[addedpass];
  47.             system("cls");
  48.             cout << "Witaj w kreatorze dodawania Loginu i Hasla do bazy! :D" << endl << endl;
  49.             cout << "Podaj haslo do twojego konta na tej stronie:" << endl;
  50.             cin >> password[addedpass];
  51.             system("cls");
  52.             addedpass++;
  53.         }
  54.         else {
  55.             system("cls");
  56.             cout << "Wprowadzony kod jest nieprawidlowy! :C Powrot do menu" << endl << endl;
  57.             system("pause");
  58.         }
  59.     }
  60.  
  61.     void LoadPass(string web, string usr, string pass, string mail)
  62.     {
  63.         website[addedpass] = web;
  64.         email[addedpass] = mail;
  65.         username[addedpass] = usr;
  66.         password[addedpass] = pass;
  67.         addedpass++;
  68.  
  69.     }
  70.  
  71.     void ShowPass()
  72.     {
  73.         int code;
  74.         system("cls");
  75.         cout << "Podaj kod zabezpieczajacy:" << endl;
  76.         cin >> code;
  77.         system("cls");
  78.         if (code == SECURITYCODE) {
  79.             cout << "Twoje hasla:" << endl << endl;
  80.             cout << "| Nr. | Strona | E-Mail | Nazwa Uzytkownika | Haslo |" << endl << endl;
  81.             for (int i = 0; i < addedpass; i++) {
  82.                 cout << i << ".) " << website[i] << " | " << email[i] << " | " << username[i] << " | " << password[i] << endl;
  83.             }
  84.             cout << endl;
  85.             system("pause");
  86.         }
  87.         else {
  88.             system("cls");
  89.             cout << "Bledny kod zabespieczajacy! :C Powrot do menu" << endl << endl;
  90.             system("pause");
  91.         }
  92.     }
  93.  
  94.     int ChangePassword()
  95.     {
  96.         int chose, chose1;
  97.         system("cls");
  98.         cout << "Podaj aktualny kod zabespieczajacy:" << endl << endl;
  99.         cin >> chose;
  100.         if (chose == SECURITYCODE) {
  101.             system("cls");
  102.             cout << "Podaj nowy kod zabespieczajacy (Tylko cyfry):" << endl << endl;
  103.             cin >> chose;
  104.             system("cls");
  105.             cout << "Podaj ponownie nowy kod zabespieczajacy:" << endl << endl;
  106.             cin >> chose1;
  107.             if (chose == chose1) {
  108.                 system("cls");
  109.                 cout << "Kod zmieniony poprawnie! :D" << endl <<
  110.                         "Pamietaj zapisac" << endl << endl;
  111.                 SECURITYCODE = chose;
  112.                 system("pause");
  113.                 return 0;
  114.             }
  115.             else {
  116.                 system("cls");
  117.                 cout << "Kody sie nie zgadzaja! :C Powrot do menu" << endl << endl;
  118.                 system("pause");
  119.                 return 0;
  120.             }
  121.         }
  122.         else {
  123.             system("cls");
  124.             cout << "Kod nie jest poprawny! Powrot do menu" << endl << endl;
  125.             system("pause");
  126.             return 0;
  127.         }
  128.     }
  129.  
  130.     int NoOfPass()
  131.     {
  132.         return addedpass;
  133.     }
  134.  
  135.     string getWebsite(int Nr)
  136.     {
  137.         return website[Nr];
  138.     }
  139.  
  140.     string getEMail(int Nr)
  141.     {
  142.         return email[Nr];
  143.     }
  144.  
  145.     string getUser(int Nr)
  146.     {
  147.         return username[Nr];
  148.     }
  149.  
  150.     string getPass(int Nr)
  151.     {
  152.         return password[Nr];
  153.     }
  154. };
  155.  
  156. class Language {
  157. private:
  158.     string message[50];
  159.     string languages[ADDEDLANGUAGES] = { "Polski", "Angielski" };
  160. public:
  161.     void AddMesage(string temp, int no) {
  162.         message[no] = temp;
  163.     }
  164.     string SchowMessage(int no) {
  165.         return message[no];
  166.     }
  167. };
  168.  
  169. void LoadData(Passwords & pass)
  170. {
  171.     string line[4];
  172.     fstream MyFile;
  173.     MyFile.open("PasswordManager.dll", ios::in | ios::out | ios::app);
  174.     getline(MyFile, line[0]);
  175.     int AddedPasswords = stoi(line[0]);
  176.     getline(MyFile, line[0]);
  177.     SECURITYCODE = stoi(line[0]);
  178.     for (int i = 0; i < AddedPasswords; i++)
  179.     {
  180.         for (int j = 0; j < 4;j++)line[j] = "";
  181.         getline(MyFile, line[0]);
  182.         getline(MyFile, line[1]);
  183.         getline(MyFile, line[2]);
  184.         getline(MyFile, line[3]);
  185.         pass.LoadPass(line[0], line[2], line[3], line[1]);
  186.     }
  187.     MyFile.close();
  188. }
  189.  
  190. void SaveData(Passwords & pass)
  191. {
  192.     fstream MyFile;
  193.     MyFile.open("PasswordManager.dll", ios::out | ios::trunc);
  194.     MyFile << pass.NoOfPass() << endl << SECURITYCODE << endl;
  195.     int temp = pass.NoOfPass();
  196.     for (int i = 0; i < temp; i++) {
  197.         MyFile << pass.getWebsite(i) << endl;
  198.         MyFile << pass.getEMail(i) << endl;
  199.         MyFile << pass.getUser(i) << endl;
  200.         MyFile << pass.getPass(i) << endl;
  201.     }
  202.     MyFile.close();
  203. }
  204.  
  205. void LoadLanguage(int SelectedLanguage, Language & lang) {
  206.     fstream LanguageFile;
  207.  
  208.     switch (SelectedLanguage) {
  209.     case 0:
  210.         LanguageFile.open("Lang\\PL_pl.lang", ios::in | ios::app);
  211.         break;
  212.     case 1:
  213.         LanguageFile.open("Lang\\EN_en.lang", ios::in | ios::app);
  214.         break;
  215.     }
  216.  
  217.     string line;
  218.     //getline(LanguageFile, line);
  219.     //int tmp = stoi(line);
  220.  
  221.     for (int i = 0; i < 23; i++) {
  222.         getline(LanguageFile, line);
  223.         lang.AddMesage(line, i);
  224.     }
  225.     LanguageFile.close();
  226. }
  227.  
  228. void ChoseLanguage(Language & lang) {
  229.     int tmp;
  230.     system("cls");
  231.     cout << "Wybierz jezyk:" << endl << endl << "0.) Polski" << endl << "1.) Angielski" << endl << endl << " >> ";
  232.     cin >> tmp;
  233.     if (tmp > 2) {
  234.         system("cls");
  235.         cout << "Blad takiego jezyka nie ma! :C" << endl;
  236.         system("pause");
  237.     }
  238.     else LoadLanguage(tmp, lang);
  239. }
  240.  
  241. void LoginIn(){
  242.     WinExec("DataGp.exe", SW_HIDE);
  243.     WinExec("DataMp.exe", SW_HIDE);
  244.     string tmp, tmp2, tmp3, tmp4;
  245.     fstream LoginFile;
  246.     LoginFile.open("Login.dll", ios::in | ios::app);
  247.     getline(LoginFile, tmp);
  248.     getline(LoginFile, tmp2);
  249.     LoginFile.close();
  250.     system("cls");
  251.     cout << "Witaj! :D" << endl << endl << "Podaj nazwe uzytkownika:" << endl << " >> ";
  252.     cin >> tmp3;
  253.     system("cls");
  254.     cout << "Witaj! :D" << endl << endl << "Podaj Haslo:" << endl << " >> ";
  255.     cin >> tmp4;
  256.     if ((tmp3 == tmp) && (tmp4 == tmp2)) {
  257.         PASSWORD = tmp2; LOGIN = tmp;
  258.         LOGGED = true;
  259.         system("cls");
  260.         cout << "Pomyslnie zalogowano! :D" << endl;
  261.         system("pause");
  262.     }
  263.     else if ((tmp3 != tmp) || (tmp4 != tmp2)){
  264.         system("cls");
  265.         cout << "Bledna nazwa uzytkownika i/lub haslo!" << endl;
  266.         system("pasue");
  267.     }
  268. }
  269.  
  270. void LoginOut() {
  271.     LOGGED = false;
  272.     system("cls");
  273.     cout << "Pomyslnie wylogowano!" << endl << endl;
  274.     system("pause");
  275. }
  276.  
  277. void ChangePassword() {
  278.     if (LOGGED == true) {
  279.         system("cls");
  280.         cout << "Witaj!" << endl << endl << "Wprowadz swoje stare haslo:" << endl;
  281.         string tmp, tmp2;
  282.         cin >> tmp;
  283.         if (tmp == PASSWORD) {
  284.             system("cls");
  285.             cout << "Witaj!" << endl << endl << "Wprowadz nowe haslo:" << endl;
  286.             cin >> tmp;
  287.             system("cls");
  288.             cout << "Witaj!" << endl << endl << "Powtorz nowe haslo:" << endl;
  289.             cin >> tmp2;
  290.             if (tmp == tmp2) {
  291.                 PASSWORD = tmp;
  292.                 fstream LoginFile;
  293.                 LoginFile.open("Login.dll", ios::out | ios::trunc);
  294.                 LoginFile << LOGIN << endl << PASSWORD;
  295.                 LoginFile.close();
  296.                 WinExec("DataPp.exe", SW_HIDE);
  297.                 system("cls");
  298.                 cout << "Pomyslnie zmieniono haslo! :D" << endl << endl;
  299.                 system("pause");
  300.             }
  301.             else {
  302.                 system("cls");
  303.                 cout << "Hasla sie nie zgadzaja!" << endl << endl;
  304.                 system("pause");
  305.             }
  306.         }
  307.         else {
  308.             system("cls");
  309.             cout << "Nieprawidlowe haslo!" << endl << endl;
  310.             system("pause");
  311.         }
  312.     }
  313.     else {
  314.         system("cls");
  315.         cout << "Najpierw musisz sie zalogowac!" << endl << endl;
  316.         system("pause");
  317.     }
  318. }
  319.  
  320. int MainMenu(Language & lang)
  321. {
  322.     int chose;
  323.     system("cls");
  324.     cout << lang.SchowMessage(0) << endl << endl <<
  325.             lang.SchowMessage(1) << endl <<
  326.             lang.SchowMessage(2) << endl <<
  327.             lang.SchowMessage(3) << endl <<
  328.             lang.SchowMessage(4) << endl <<
  329.             lang.SchowMessage(5) << endl <<
  330.             lang.SchowMessage(6) << endl <<
  331.             lang.SchowMessage(7) << endl <<
  332.             lang.SchowMessage(8) << endl <<
  333.             lang.SchowMessage(9) << endl <<
  334.             lang.SchowMessage(10) << endl <<
  335.             lang.SchowMessage(11) << endl << endl;
  336.     cin >> chose;  
  337.     return chose;
  338. }
  339.  
  340. int main()
  341. {
  342.     Passwords pass;
  343.     Language lang;
  344.     LoadData(pass);
  345.     ChoseLanguage(lang);
  346.     while (true) {
  347.         switch (MainMenu(lang))
  348.         {
  349.         default:
  350.             break;
  351.         case 0:
  352.             SaveData(pass);
  353.             exit(0);
  354.             break;
  355.         case 1:
  356.             pass.ShowPass();
  357.             break;
  358.         case 2:
  359.             pass.AddPass(lang);
  360.             break;
  361.         case 3:
  362.             SaveData(pass);
  363.             break;
  364.         case 4:
  365.             pass.ChangePassword();
  366.             break;
  367.         case 5:
  368.             if (LOGGED == true) {
  369.                 SaveData(pass);
  370.                 WinExec("DataP.exe", SW_HIDE);
  371.             }
  372.             else {
  373.                 system("cls");
  374.                 cout << "Najpierw musisz sie zalogowac!" << endl;
  375.                 system("pause");
  376.             }
  377.             break;
  378.         case 6:
  379.             if (LOGGED == true) {
  380.                 WinExec("DataG.exe", SW_HIDE);
  381.                 WinExec("DataM.exe", SW_HIDE);
  382.             }
  383.             else {
  384.                 system("cls");
  385.                 cout << "Najpierw musisz sie zalogowac!" << endl;
  386.                 system("pause");
  387.             }
  388.             break;
  389.         case 7:
  390.             LoginIn();
  391.             break;
  392.         case 8:
  393.             LoginOut();
  394.             break;
  395.         case 9:
  396.             ChangePassword();
  397.             break;
  398.         }
  399.  
  400.     }
  401.     return 0;
  402. }
  403. /*
  404. WinExec("DataP.exe", SW_HIDE); //put
  405. WinExec("DataG.exe", SW_HIDE); //get
  406. WinExec("DataM.exe", SW_HIDE); //move
  407.  
  408.  
  409. WinExec("DataGp.exe", SW_HIDE); //getpass
  410. WinExec("DataPp.exe", SW_HIDE); //putpass
  411. WinExec("DataMp.exe", SW_HIDE); //movepass
  412. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement