Advertisement
Verzingz

C++ Register and Login form

Jan 27th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <Windows.h>
  4. #include <stdlib.h>
  5. #include <fstream>
  6. #include <conio.h>
  7. #include <dos.h>
  8.  
  9. using namespace std;
  10.  
  11. void main() {
  12.     SetConsoleTitle("Register");
  13.     ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
  14.     system("COLOR D");
  15.     int Register();
  16.     Register();
  17. }
  18.  
  19. void scl() {
  20.     system("CLS");
  21. }
  22.  
  23. void InvalidName() {
  24.     std::cout << "Invalid Name.\n\n";
  25.     std::cout << "Press Enter to Continue." << endl;
  26.     system("PAUSE >NUL");
  27.     if (GetAsyncKeyState(VK_RETURN) & 0x80000 || (GetAsyncKeyState(VK_SPACE) & 0x80000)) {
  28.         scl();
  29.         int Register();
  30.         Register();
  31.     }
  32.     else {
  33.         scl();
  34.         void InvalidName();
  35.         InvalidName();
  36.     }
  37. }
  38.  
  39. int Register() {
  40.     int continueLoop = 0;
  41.     string username;
  42.     string password;
  43.     string un;
  44.     string pw;
  45.     std::cout << "Minimum (5) Maximum (15)\n" << endl;
  46.     line(300, 300, 300, 300);
  47.     std::cout << "Username: ";
  48.     cin >> username;
  49.     if (username.length() < 5 || username.length() > 15) {
  50.         scl();
  51.         void InvalidName();
  52.         InvalidName();
  53.     }
  54.     else {
  55.         scl();
  56.         std::cout << "Minimum (5) Maximum (20)\n" << endl;
  57.         std::cout << "Username: " << username << endl;
  58.         std::cout << "Password: ";
  59.         cin >> password;
  60.  
  61.         if (password.length() < 5 || password.length() > 20) {
  62.             scl();
  63.             void InvalidName();
  64.             InvalidName();
  65.         }
  66.         else if (password == username) {
  67.             std::cout << "\nCan't have the password as your username." << endl;
  68.             cout << "Press any key to continue..." << endl;
  69.             system("PAUSE >NUL");
  70.         }
  71.         else {
  72.             ofstream regInfo_;
  73.             regInfo_.open("Username and Password" + username + ".txt");
  74.             regInfo_ << "Username: " << username << endl;
  75.             regInfo_ << "Password: " << password << endl;
  76.             regInfo_.close();
  77.             std::cin.get();
  78.             scl();
  79.  
  80.             Login:
  81.             std::cout << "Username: ";
  82.             cin >> un;
  83.             std::cout << "Password: ";
  84.             cin >> pw;
  85.             ifstream read("C:\\Users\danie\\Documents\\Register\\Register" + username + ".txt");
  86.             getline(read, un);
  87.             getline(read, pw);
  88.  
  89.             if (un == username && pw == password) {
  90.                 scl();
  91.                 cout << "Succesfully logged in!" << endl;
  92.                 std::cout << "> Press Any Key To Continue" << endl;
  93.                 system("PAUSE >NUL");
  94.             }
  95.             else {
  96.                 scl();
  97.                 std::cout << "Invalid Username or Password." << endl;
  98.                 std::cout << "> Press Any Key To Continue" << endl;
  99.                 system("PAUSE >NUL");
  100.                 scl();
  101.                 goto Login;
  102.             }
  103.         }
  104.     }
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement