Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <iostream>
  5. #include <math.h>
  6. #include <conio.h>
  7. using namespace std;
  8.  
  9.  
  10. void Generuj(string& haslo);
  11. void Wprowadz(string haslo);
  12.  
  13. int main()
  14. {
  15.     int Wybor=1;
  16.     string haslo = "";
  17.  
  18.     while(Wybor == 1 || Wybor ==2 )
  19.     {
  20.         cout << "MENU" << endl;
  21.         cout << "1 - Generuj haslo" << endl;
  22.         cout << "2 - Wprowadz haslo" << endl;
  23.         cout << "Donowlny znak aby zakonczyc" << endl;
  24.         cout << endl;
  25.         cout << "Twoj wybor: ";
  26.         cin >> Wybor; system("cls");
  27.  
  28.         switch (Wybor)
  29.         {
  30.             case 1:
  31.                 Generuj(haslo); break;
  32.  
  33.             case 2:
  34.                 Wprowadz(haslo); break;
  35.  
  36.             default: cout << "Koniec programu."; break;
  37.         }
  38.     }
  39.     system("pause");
  40. }
  41. void Generuj(string& haslo)
  42. {
  43.     string wybor2 = "tak";
  44.     while (wybor2 == "tak")
  45.     {
  46.         int n;
  47.         cout << "Ile znakow ma miec twoje haslo? ";
  48.  
  49.         cin >> n;
  50.         string haslo = "";
  51.         srand(time(NULL));
  52.  
  53.         for (int i = 0; i < n; i++)
  54.         {
  55.             char a = rand() % 94 + 33;
  56.             haslo += a;
  57.         }
  58.  
  59.         cout << haslo << endl;
  60.         cout << "Czy chcesz wygenerowac nowe haslo?" << endl;
  61.         cout << "wprowadz tak lub nie: ";
  62.         cin >> wybor2;
  63.     }
  64. }
  65. void Wprowadz(string haslo)
  66. {
  67.     cout << haslo;
  68.     string wybor3 = "tak";
  69.     while (wybor3 == "tak")
  70.     {
  71.         cout << haslo;
  72.         cout << "Wprowadz wygenerowane haslo: ";
  73.  
  74.         string haslo1 = "";
  75.         char c = ' ';
  76.  
  77.         while (c != 13) //Petla az enter zostanie wcisniety
  78.         {
  79.             c = _getch();
  80.             if(c!=13)
  81.                 haslo1 += c;
  82.                 cout << "*";
  83.         }
  84.         cout << endl << haslo1 << endl; //
  85.  
  86.         cout << "Wprowadz ponownie wygenerowane haslo: ";
  87.  
  88.         string haslo2 = "";
  89.         char b = ' ';
  90.  
  91.         while (b != 13)
  92.         {
  93.             b = _getch();
  94.             if (b != 13)
  95.             {
  96.                 haslo2 += b;
  97.                 //cout << "*";
  98.             }
  99.         }
  100.         cout << endl << haslo2 << endl; //
  101.  
  102.         if ((haslo1 == haslo) && (haslo2 == haslo)) cout << "Prawidlowo wpisales haslo! :)";
  103.        
  104.         else cout << "Nieprawidlowo wpisales haslo! :(" << endl;
  105.         cout << "haslo = " << haslo << " lenght = " << haslo.length() << endl;
  106.         cout << "haslo1 = " << haslo1 << " lenght = " << haslo1.length() << endl;
  107.         cout << "haslo2 = " << haslo2 << " lenght = " << haslo2.length() << endl;
  108.         cout << "Czy chcesz sprobowac jeszcze raz? " << endl;
  109.         cout << "wprowadz tak lub nie: ";
  110.         cin >> wybor3;
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement