πŸš€ C++ Modern GUI Login System for Windows - Stylish & Lightweight (Source Code Included)

Demo :


Click Video πŸ‘‡πŸ‘‡πŸ‘‡














πŸ”₯ Modern C++ GUI Login System for Windows! This tutorial helps you create a fully interactive login system with a stylish Windows GUI (No Console, Full UI).

πŸ“Œ Features:
Windows-Based GUI (No Console Window)
User Registration, Login & Password Recovery
Modern UI with Buttons, Text Fields, & Message Boxes
Lightweight & Fast (Uses WinAPI, No Extra Libraries)
Step-by-Step Guide & Full Source Code Provided

πŸ“₯ Download Source Code & Full Guide Here πŸ‘‡

Code :


#include <windows.h>

#include <fstream>

#include <string>


using namespace std;


LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);

void RegisterUser(HWND);

void LoginUser(HWND);

void ForgotPassword(HWND);


// Global UI Elements

HWND hUsername, hPassword, hRegister, hLogin, hForgot, hLabel;


void CreateMainWindow(HWND hwnd) {

    // Labels

    CreateWindow("STATIC", "Username:", WS_VISIBLE | WS_CHILD, 20, 20, 80, 25, hwnd, NULL, NULL, NULL);

    CreateWindow("STATIC", "Password:", WS_VISIBLE | WS_CHILD, 20, 60, 80, 25, hwnd, NULL, NULL, NULL);


    // Input Fields

    hUsername = CreateWindow("EDIT", "", WS_VISIBLE | WS_CHILD | WS_BORDER, 100, 20, 200, 25, hwnd, NULL, NULL, NULL);

    hPassword = CreateWindow("EDIT", "", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_PASSWORD, 100, 60, 200, 25, hwnd, NULL, NULL, NULL);


    // Buttons

    hRegister = CreateWindow("BUTTON", "Register", WS_VISIBLE | WS_CHILD, 20, 100, 90, 30, hwnd, (HMENU)1, NULL, NULL);

    hLogin = CreateWindow("BUTTON", "Login", WS_VISIBLE | WS_CHILD, 130, 100, 90, 30, hwnd, (HMENU)2, NULL, NULL);

    hForgot = CreateWindow("BUTTON", "Forgot Password", WS_VISIBLE | WS_CHILD, 240, 100, 130, 30, hwnd, (HMENU)3, NULL, NULL);

}


void RegisterUser(HWND hwnd) {

    char username[30], password[30];

    GetWindowText(hUsername, username, 30);

    GetWindowText(hPassword, password, 30);


    ofstream file("users.txt", ios::app);

    file << username << " " << password << endl;

    file.close();


    MessageBox(hwnd, "Registration Successful!", "Success", MB_OK | MB_ICONINFORMATION);

}


void LoginUser(HWND hwnd) {

    char username[30], password[30], u[30], p[30];

    GetWindowText(hUsername, username, 30);

    GetWindowText(hPassword, password, 30);


    ifstream file("users.txt");

    while (file >> u >> p) {

        if (strcmp(u, username) == 0 && strcmp(p, password) == 0) {

            MessageBox(hwnd, "Login Successful!", "Success", MB_OK | MB_ICONINFORMATION);

            return;

        }

    }

    file.close();

    MessageBox(hwnd, "Invalid Username or Password!", "Error", MB_OK | MB_ICONERROR);

}


void ForgotPassword(HWND hwnd) {

    char username[30], u[30], p[30];

    GetWindowText(hUsername, username, 30);


    ifstream file("users.txt");

    while (file >> u >> p) {

        if (strcmp(u, username) == 0) {

            MessageBox(hwnd, (string("Your Password: ") + p).c_str(), "Password Found", MB_OK | MB_ICONINFORMATION);

            return;

        }

    }

    file.close();

    MessageBox(hwnd, "Username not found!", "Error", MB_OK | MB_ICONERROR);

}


LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {

    switch (msg) {

        case WM_CREATE:

            CreateMainWindow(hwnd);

            break;

        case WM_COMMAND:

            switch (wp) {

                case 1: RegisterUser(hwnd); break;

                case 2: LoginUser(hwnd); break;

                case 3: ForgotPassword(hwnd); break;

            }

            break;

        case WM_DESTROY:

            PostQuitMessage(0);

            break;

        default:

            return DefWindowProc(hwnd, msg, wp, lp);

    }

    return 0;

}


int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR args, int ncmdshow) {

    WNDCLASS wc = { 0 };

    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;

    wc.hCursor = LoadCursor(NULL, IDC_ARROW);

    wc.hInstance = hInst;

    wc.lpfnWndProc = WindowProcedure;

    wc.lpszClassName = "LoginApp";


    if (!RegisterClass(&wc)) return -1;


    HWND hwnd = CreateWindow("LoginApp", "Modern Login System", WS_OVERLAPPEDWINDOW | WS_VISIBLE,

        100, 100, 400, 200, NULL, NULL, NULL, NULL);


    MSG msg;

    while (GetMessage(&msg, NULL, 0, 0)) {

        TranslateMessage(&msg);

        DispatchMessage(&msg);

    }


    return 0;

}


πŸ”” Stay Updated! Subscribe to Our YouTube for More Coding Content! πŸš€

Comments

Popular posts from this blog

Is This News Real or Fake? πŸ€– AI Exposes the Truth | FuzzuTech Python App Demo

🚨 Python Intrusion Detection System (IDS) – Real-Time ML + Tkinter GUI Project | FuzzuTech

πŸš€ Simple Login & Registration System in Python Tkinter πŸ“±