Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cctype>
- #include <conio.h>
- #include <cstring>
- #include <stdlib.h>
- using namespace std;
- int main()
- {
- string user, password, userConfirmation, passwordConfirmation;
- string alphaUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- string alphaLower = "abcdefghijklmnopqrstuvwxyz";
- string numer = "0123456789";
- string symbols = "!@#$%^&*_+|-=:;,<.>/? ";
- string letter;
- char passwordTemp, passwordConfTemp;
- 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;
- while (check1 != 0)
- {
- cout<<"REGISTRATION\n";
- cout<<"Username: ";
- getline(cin, user);
- system("cls");
- cout<<"REGISTRATION\n";
- cout<<"Username: "<<user<<endl;
- cout<<"Password: ";
- while (check2 != 0)
- {
- for ( ; ; )
- {
- passwordTemp = getch();
- if (passwordTemp == '\r')
- {
- break;
- }
- if (passwordTemp == '\b')
- {
- password.erase((password.length() - 1), 1);
- cout<<'\b';
- cout<<" ";
- cout<<'\b';
- continue;
- }
- password += passwordTemp;
- cout<<"*";
- }
- cout<<endl<<password<<"<<FOR TESTING"<< endl;
- break;
- }
- length = password.length();
- // checks if password is within 6-10 characters, repeats loop if not
- if ((length < 6) || (length > 10))
- {
- cout<<"Your password length must be within 6-10 characters.";
- password.clear();
- user.clear();
- system("pause");
- system("cls");
- continue;
- }
- for (int y = 0; y < 22; y++)
- {
- for (int z = 0; z < length; z++)
- {
- letter = password.substr(z, 1);
- if (letter == symbols.substr(y, 1))
- {
- symCount += 1;
- break;
- }
- }
- }
- for (int a = 0; a < 25; a++)
- {
- for (int b = 0; b < length; b++)
- {
- letter = password.substr(b, 1);
- if (letter == alphaUpper.substr(a, 1))
- {
- aUpCount += 1;
- break;
- }
- }
- }
- for (int c = 0; c < 25; c++)
- {
- for (int d = 0; d < length; d++)
- {
- letter = password.substr(d, 1);
- if (letter == alphaLower.substr(c, 1))
- {
- aLowCount += 1;
- break;
- }
- }
- }
- for (int e = 0; e < 10; e++)
- {
- for (int f = 0; f < length; f++)
- {
- letter = password.substr(f, 1);
- if (letter == numer.substr(e, 1))
- {
- aNumCount += 1;
- }
- }
- }
- if (aUpCount > 0)
- {
- aUpVer += 1;
- }
- if (aLowCount > 0)
- {
- aLowVer += 1;
- }
- if (aNumCount > 0)
- {
- aNumVer += 1;
- }
- if ((aUpVer != 1) || (aLowVer != 1) || (aNumVer != 1))
- {
- cout<<"Your password is invalid due to the following reasons: "<<endl;
- if (aUpVer != 1)
- {
- cout<<" - There must be at least one (1) uppercase letter."<<endl;
- aUpCount = 0;
- aUpVer = 0;
- }
- if (aLowVer != 1)
- {
- cout<<" - There must be at least one (1) lowercase letter."<<endl;
- aLowVer = 0;
- aLowCount = 0;
- }
- if (aNumVer != 1)
- {
- cout<<" - There must be at least one (1) number."<<endl;
- aNumVer = 0;
- aNumCount = 0;
- }
- if (symCount > 0)
- {
- cout<<" - Your password cannot contain any special characters."<<endl;
- symCount = 0;
- }
- password.clear();
- system("pause");
- system("cls");
- continue;
- }
- cout<<endl<<"Details recorded.";
- system("pause");
- system("cls");
- goto verification;
- }
- verification:
- cout<<"Your login details are up for verification."<<endl;
- while(check3 != 0)
- {
- cout<<"VERIFICATION: \n";
- cout<<"Username :";
- getline(cin, userConfirmation);
- system("cls");
- cout<<"VERIFICATION: \n";
- cout<<"Username: "<<userConfirmation<<endl;
- cout<<"Password: ";
- while (check2 != 0)
- {
- for ( ; ; )
- {
- passwordConfTemp = getch();
- if (passwordConfTemp == '\r')
- {
- break;
- }
- passwordConfirmation += passwordConfTemp;
- cout<<"*";
- }
- cout<<endl<<passwordConfirmation<<"<<FOR TESTING"<< endl;
- break;
- }
- if (userConfirmation != user)
- {
- userVer += 1;
- }
- if (passwordConfirmation != password)
- {
- passwordVer += 1;
- }
- if ((userVer > 0) || (passwordVer > 0))
- {
- cout<<"Verification failed due to the following reasons: ";
- if (userVer > 0)
- {
- cout<<endl<<" - The username does not match the previous one you entered."<<endl;
- userVer = 0;
- }
- if (passwordVer > 0)
- {
- cout<<endl<<" - The password does not match the previous one you entered."<<endl;
- passwordVer = 0;
- }
- passwordConfirmation.clear();
- userConfirmation.clear();
- system("pause");
- system("cls");
- continue;
- }
- cout<<endl<<"Success!"<<endl;
- cout<<"Your account has been registered."<<endl;
- goto end;
- }
- end:
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement