Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IMGUI/imgui-SFML.h>
- #include "Game.h"
- #include "Window.h"
- #include "Crypt.h"
- struct account_t userAccount = { 0 };
- bool RegWindow = false;
- bool RegWindowSetup = false;
- void LogonWindow(_GAME *pGame)
- {
- static char szUsernameIn[32] = { 0 }, szPasswordIn[32] = { 0 };
- ImGui::SetNextWindowPos(ImVec2(1360 / 2 - 100, 720 / 2 - 75));
- ImGui::SetNextWindowSize(ImVec2(215, 125));
- ImGui::Begin("User login", 0, ImGuiWindowFlags_NoResize);
- ImGui::Text("HL Alpha");
- ImGui::InputText("Username", szUsernameIn, 32);
- ImGui::InputText("Password", szPasswordIn, 32);
- if (ImGui::Button("Login"))
- {
- readAccountDataFromFile((char*)"hl_u.dat", &userAccount, sizeof(struct account_t));
- encryptData((unsigned char*)&userAccount, sizeof(struct account_t));
- if (strcmp(szUsernameIn, userAccount.szUsername) == 0 && strcmp(szPasswordIn, userAccount.szPassword) == 0)
- std::cout << "Login successful.\n";
- else
- std::cout << "Wrong username / password.\n";
- }
- ImGui::SameLine();
- // Create new user
- if (ImGui::Button("New User"))
- RegWindow = true;
- if (RegWindow)
- LogonWindow_Register(pGame);
- ImGui::End();
- }
- void LogonWindow_Register(_GAME *pGame)
- {
- static char szUsernameIn[32] = { 0 }, szPasswordIn[32] = { 0 };
- ImGui::SetNextWindowPos(ImVec2(1360 / 2 - 100, 720 / 2 - 75));
- ImGui::SetNextWindowSize(ImVec2(235, 135));
- ImGui::Begin("Register User", 0, ImGuiWindowFlags_NoResize);
- ImGui::InputText("Username", userAccount.szUsername, 32);
- ImGui::InputText("Password", userAccount.szPassword, 32);
- if (ImGui::Button("Register")){
- // Encrypt password and write it to file.B
- encryptData((unsigned char*)&userAccount, sizeof(struct account_t));
- saveAccountDataToFile((char*)"hl_u.dat", (void*)&userAccount, sizeof(struct account_t));
- // Bugfix - Reset textboxes to prevent it from showing encrypted password.
- strcpy(userAccount.szUsername, "");
- strcpy(userAccount.szPassword, "");
- RegWindow = false;
- }
- ImGui::SameLine();
- // Close current form (Registration of new user)
- if (ImGui::Button("Close"))
- RegWindow = false;
- if (RegWindowSetup)
- LogonWindow_RegisterSetup(pGame);
- ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(5, 0, 0, 0.5));
- ImGui::Text("Please do not use your private \npasswords.");
- ImGui::PopStyleColor(1);
- ImGui::End();
- }
- void LogonWindow_RegisterSetup(_GAME *pGame)
- {
- ImGui::SetNextWindowPos(ImVec2(1360 / 2 - 100, 720 / 2 - 75));
- ImGui::SetNextWindowSize(ImVec2(265, 105));
- ImGui::Begin("New User Setup", 0, ImGuiWindowFlags_NoResize);
- ImGui::Text("Setting up HLOS for the first time.");
- ImGui::Text("Status: "); ImGui::SameLine();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement