SHARE
TWEET

Untitled

a guest Sep 16th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <IMGUI/imgui-SFML.h>
  3. #include "Game.h"
  4. #include "Window.h"
  5. #include "Crypt.h"
  6.  
  7. struct account_t userAccount = { 0 };
  8.  
  9. bool RegWindow = false;
  10. bool RegWindowSetup = false;
  11.  
  12. void LogonWindow(_GAME *pGame)
  13. {
  14.     static char szUsernameIn[32] = { 0 }, szPasswordIn[32] = { 0 };
  15.    
  16.     ImGui::SetNextWindowPos(ImVec2(1360 / 2 - 100, 720 / 2 - 75));
  17.     ImGui::SetNextWindowSize(ImVec2(215, 125));
  18.    
  19.     ImGui::Begin("User login", 0, ImGuiWindowFlags_NoResize);
  20.    
  21.     ImGui::Text("HL Alpha");
  22.     ImGui::InputText("Username", szUsernameIn, 32);
  23.     ImGui::InputText("Password", szPasswordIn, 32);
  24.    
  25.     if (ImGui::Button("Login"))
  26.     {
  27.        
  28.         readAccountDataFromFile((char*)"hl_u.dat", &userAccount, sizeof(struct account_t));
  29.         encryptData((unsigned char*)&userAccount, sizeof(struct account_t));
  30.        
  31.         if (strcmp(szUsernameIn, userAccount.szUsername) == 0 && strcmp(szPasswordIn, userAccount.szPassword) == 0)
  32.             std::cout << "Login successful.\n";
  33.         else
  34.             std::cout << "Wrong username / password.\n";
  35.     }
  36.  
  37.     ImGui::SameLine();
  38.  
  39.     // Create new user
  40.     if (ImGui::Button("New User"))
  41.         RegWindow = true;      
  42.  
  43.     if (RegWindow)
  44.         LogonWindow_Register(pGame);
  45.  
  46.     ImGui::End();
  47. }
  48.  
  49. void LogonWindow_Register(_GAME *pGame)
  50. {
  51.     static char szUsernameIn[32] = { 0 }, szPasswordIn[32] = { 0 };
  52.  
  53.     ImGui::SetNextWindowPos(ImVec2(1360 / 2 - 100, 720 / 2 - 75));
  54.     ImGui::SetNextWindowSize(ImVec2(235, 135));
  55.  
  56.     ImGui::Begin("Register User", 0, ImGuiWindowFlags_NoResize);
  57.  
  58.     ImGui::InputText("Username", userAccount.szUsername, 32);
  59.     ImGui::InputText("Password", userAccount.szPassword, 32);
  60.    
  61.     if (ImGui::Button("Register")){
  62.         // Encrypt password and write it to file.B
  63.         encryptData((unsigned char*)&userAccount, sizeof(struct account_t));
  64.         saveAccountDataToFile((char*)"hl_u.dat", (void*)&userAccount, sizeof(struct account_t));
  65.        
  66.         // Bugfix - Reset textboxes to prevent it from showing encrypted password.
  67.         strcpy(userAccount.szUsername, "");
  68.         strcpy(userAccount.szPassword, "");
  69.        
  70.         RegWindow = false;
  71.     }
  72.     ImGui::SameLine();
  73.  
  74.     // Close current form (Registration of new user)
  75.     if (ImGui::Button("Close"))
  76.         RegWindow = false;
  77.  
  78.     if (RegWindowSetup)
  79.         LogonWindow_RegisterSetup(pGame);
  80.  
  81.     ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(5, 0, 0, 0.5));
  82.     ImGui::Text("Please do not use your private \npasswords.");
  83.     ImGui::PopStyleColor(1);
  84.    
  85.     ImGui::End();
  86. }
  87.  
  88. void LogonWindow_RegisterSetup(_GAME *pGame)
  89. {
  90.     ImGui::SetNextWindowPos(ImVec2(1360 / 2 - 100, 720 / 2 - 75));
  91.     ImGui::SetNextWindowSize(ImVec2(265, 105));
  92.     ImGui::Begin("New User Setup", 0, ImGuiWindowFlags_NoResize);
  93.     ImGui::Text("Setting up HLOS for the first time.");
  94.     ImGui::Text("Status: "); ImGui::SameLine();
  95. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top