Advertisement
rexinsteroids

Registration_DGJP_Final

Apr 8th, 2019
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3. #include <conio.h>
  4. #include <cstring>
  5. #include <stdlib.h>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     string user, password, userConfirmation, passwordConfirmation;
  11.     string alphaUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  12.     string alphaLower = "abcdefghijklmnopqrstuvwxyz";
  13.     string numer = "0123456789";
  14.     string symbols = "!@#$%^&*_+|-=:;,<.>/? ";
  15.     string letter;
  16.     char passwordTemp, passwordConfTemp;
  17.     int length, check1 = 1, check2 = 1, check3 = 1, aUpCount = 0, aUpVer = 0, aLowCount = 0, aLowVer = 0, aNumCount = 0, aNumVer = 0, userVer = 0, passwordVer = 0, symCount = 0;
  18.  
  19.  
  20.     while (check1 != 0)
  21.     {
  22.     cout<<"REGISTRATION\n";
  23.     cout<<"Username: ";
  24.     getline(cin, user);
  25.     system("cls");
  26.     cout<<"REGISTRATION\n";
  27.     cout<<"Username: "<<user<<endl;
  28.     cout<<"Password: ";
  29.         while (check2 != 0)
  30.         {
  31.             for ( ; ; )
  32.             {
  33.                 passwordTemp = getch();
  34.                 if (passwordTemp == '\r')
  35.                 {
  36.                     break;
  37.                 }
  38.                 if (passwordTemp == '\b')
  39.                 {
  40.                     password.erase((password.length() - 1), 1);
  41.                     cout<<'\b';
  42.                     cout<<" ";
  43.                     cout<<'\b';
  44.                     continue;
  45.                 }
  46.                 password += passwordTemp;
  47.                 cout<<"*";
  48.             }
  49.             cout<<endl<<password<<"<<FOR TESTING"<< endl;
  50.             break;
  51.         }
  52.         length = password.length();
  53.  
  54.         // checks if password is within 6-10 characters, repeats loop if not
  55.         if ((length < 6) || (length > 10))
  56.         {
  57.             cout<<"Your password length must be within 6-10 characters.";
  58.             password.clear();
  59.             user.clear();
  60.             system("pause");
  61.             system("cls");
  62.             continue;
  63.         }
  64.  
  65.         for (int y = 0; y < 22; y++)
  66.         {
  67.             for (int z = 0; z < length; z++)
  68.             {
  69.                 letter = password.substr(z, 1);
  70.                 if (letter == symbols.substr(y, 1))
  71.                 {
  72.                     symCount += 1;
  73.                     break;
  74.                 }
  75.             }
  76.         }
  77.         for (int a = 0; a < 25; a++)
  78.         {
  79.             for (int b = 0; b < length; b++)
  80.             {
  81.                 letter = password.substr(b, 1);
  82.                 if (letter == alphaUpper.substr(a, 1))
  83.                 {
  84.                     aUpCount += 1;
  85.                     break;
  86.                 }
  87.             }
  88.         }
  89.         for (int c = 0; c < 25; c++)
  90.         {
  91.             for (int d = 0; d < length; d++)
  92.             {
  93.                 letter = password.substr(d, 1);
  94.                 if (letter == alphaLower.substr(c, 1))
  95.                 {
  96.                     aLowCount += 1;
  97.                     break;
  98.                 }
  99.             }
  100.         }
  101.         for (int e = 0; e < 10; e++)
  102.         {
  103.             for (int f = 0; f < length; f++)
  104.             {
  105.                 letter = password.substr(f, 1);
  106.                 if (letter == numer.substr(e, 1))
  107.                 {
  108.                     aNumCount += 1;
  109.                 }
  110.             }
  111.         }
  112.  
  113.         if (aUpCount > 0)
  114.         {
  115.             aUpVer += 1;
  116.         }
  117.  
  118.         if (aLowCount > 0)
  119.         {
  120.             aLowVer += 1;
  121.         }
  122.  
  123.         if (aNumCount > 0)
  124.         {
  125.             aNumVer += 1;
  126.         }
  127.  
  128.         if ((aUpVer != 1) || (aLowVer != 1) || (aNumVer != 1))
  129.         {
  130.             cout<<"Your password is invalid due to the following reasons: "<<endl;
  131.             if (aUpVer != 1)
  132.             {
  133.                 cout<<" - There must be at least one (1) uppercase letter."<<endl;
  134.                 aUpCount = 0;
  135.                 aUpVer = 0;
  136.             }
  137.             if (aLowVer != 1)
  138.             {
  139.                 cout<<" - There must be at least one (1) lowercase letter."<<endl;
  140.                 aLowVer = 0;
  141.                 aLowCount = 0;
  142.             }
  143.             if (aNumVer != 1)
  144.             {
  145.                 cout<<" - There must be at least one (1) number."<<endl;
  146.                 aNumVer = 0;
  147.                 aNumCount = 0;
  148.             }
  149.             if (symCount > 0)
  150.             {
  151.                 cout<<" - Your password cannot contain any special characters."<<endl;
  152.                 symCount = 0;
  153.             }
  154.             password.clear();
  155.             system("pause");
  156.             system("cls");
  157.             continue;
  158.         }
  159.         cout<<endl<<"Details recorded.";
  160.         system("pause");
  161.         system("cls");
  162.         goto verification;
  163.     }
  164.  
  165.     verification:
  166.     cout<<"Your login details are up for verification."<<endl;
  167.     while(check3 != 0)
  168.     {
  169.         cout<<"VERIFICATION: \n";
  170.         cout<<"Username :";
  171.         getline(cin, userConfirmation);
  172.         system("cls");
  173.         cout<<"VERIFICATION: \n";
  174.         cout<<"Username: "<<userConfirmation<<endl;
  175.         cout<<"Password: ";
  176.         while (check2 != 0)
  177.         {
  178.             for ( ; ; )
  179.             {
  180.                 passwordConfTemp = getch();
  181.                 if (passwordConfTemp == '\r')
  182.                 {
  183.                     break;
  184.                 }
  185.                 passwordConfirmation += passwordConfTemp;
  186.                 cout<<"*";
  187.             }
  188.             cout<<endl<<passwordConfirmation<<"<<FOR TESTING"<< endl;
  189.             break;
  190.         }
  191.         if (userConfirmation != user)
  192.         {
  193.             userVer += 1;
  194.         }
  195.         if (passwordConfirmation != password)
  196.         {
  197.             passwordVer += 1;
  198.         }
  199.         if ((userVer > 0) || (passwordVer > 0))
  200.         {
  201.             cout<<"Verification failed due to the following reasons: ";
  202.             if (userVer > 0)
  203.             {
  204.                 cout<<endl<<" - The username does not match the previous one you entered."<<endl;
  205.                 userVer = 0;
  206.             }
  207.             if (passwordVer > 0)
  208.             {
  209.                 cout<<endl<<" - The password does not match the previous one you entered."<<endl;
  210.                 passwordVer = 0;
  211.  
  212.             }
  213.             passwordConfirmation.clear();
  214.             userConfirmation.clear();
  215.             system("pause");
  216.             system("cls");
  217.             continue;
  218.         }
  219.         cout<<endl<<"Success!"<<endl;
  220.         cout<<"Your account has been registered."<<endl;
  221.         goto end;
  222.     }
  223.  
  224.     end:
  225.     return 0;
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement