Thread: PAssword

  1. #1
    Banned
    Join Date
    Oct 2004
    Posts
    250

    PAssword

    im trying to make a password protection program but it always says wrong password here's my code
    Code:
    case WM_COMMAND:
    		switch(LOWORD(wParam))
    		{
    		case BUTTON3:
                char passcheck [256];
    			GetWindowText(hwndEdt2,passcheck,256);
    
    			if(strcmp(passcheck, "ofp")==0)
    			{
    				MessageBox(NULL,"Password Correct", "Message", MB_OK|MB_ICONQUESTION);
    			}
    			else
    			{
    				MessageBox(NULL,"Password Incorrect", "Message", MB_OK|MB_ICONQUESTION);
    			}
    			break;
    		}
    		break;

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    What does GetWindowText() return?
    So what does passcheck contain?

    gg

  3. #3
    Banned
    Join Date
    Oct 2004
    Posts
    250
    passcheck contains whats in the editbox containing the password the user entered

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Then all you have to do is type "ofp" into the edit box, then click "BUTTON3".

    gg

  5. #5
    Banned
    Join Date
    Oct 2004
    Posts
    250
    thats the problem it always returns false password

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Use sendmessage with WM_GETTEXT, and display the data returned in a messagebox. That is, if you don't know how to debug..?

  7. #7
    Banned
    Join Date
    Oct 2004
    Posts
    250
    here is the code i have so far please help me finish this nothing i do seems to work
    all i need to do i get the text out of the editbox and compare it to the password to see if it is correct
    Code:
    #include <windows.h>
    #include <cstring>
    #include <iostream>
    using namespace std;
    
    #define EDIT1 5001
    #define EDIT2 5002
    #define BUTTON3 5003
    #define GROUP4 5004
    
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
    	case WM_CREATE:
    		CreateWindowEx(0,
    			TEXT("STATIC"),
    			TEXT("Password Protector 1.0\nPlease enter your password."),
    			WS_CHILD|WS_VISIBLE,
    			30,
    			100,
    			200,
    			30,
    			hwnd,
    			(HMENU)EDIT1,
    			NULL,
    			NULL);
    		CreateWindowEx(0,
    			TEXT("EDIT"),
    			NULL,
    			WS_CHILD|WS_VISIBLE|WS_BORDER|ES_PASSWORD,
    			30,
    			60,
    			100,
    			30,
    			hwnd,
    			(HMENU)EDIT2,
    			NULL,
    			NULL);
    		CreateWindowEx(0,
    			TEXT("BUTTON"),
    			TEXT("Enter"),
    			WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
    			150,
    			60,
    			90,
    			40,
    			hwnd,
    			(HMENU)BUTTON3,
    			NULL,
    			NULL);
    		CreateWindowEx(0,
    			TEXT("BUTTON"),
    			TEXT("Main"),
    			WS_CHILD|WS_VISIBLE|BS_GROUPBOX,
    			10,
    			10,
    			270,
    			140,
    			hwnd,
    			(HMENU)GROUP4,
    			NULL,
    			NULL);
    		break;
    		return 0;
    			
            case WM_CLOSE:
                DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
                PostQuitMessage(0);
            break;
            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX wc;
        HWND hwnd;
        MSG Msg;
    
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_BTNSHADOW);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = "WindowClass";
        wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
        if(!RegisterClassEx(&wc))
        {
            MessageBox(NULL, "Window Registration Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        hwnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            "WindowClass",
            "PassPro 1.0",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, 300, 200,
            NULL, NULL, hInstance, NULL);
    
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
    
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;
    }

  8. #8
    Banned
    Join Date
    Oct 2004
    Posts
    250
    i got it working i was getting the text wrong GetDlgItemText(); was the solution does anyone know how i could make this program automatically start up when a folder is opended?

  9. #9
    Registered User
    Join Date
    Feb 2002
    Posts
    329

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading a password from a file.
    By medeshago in forum C Programming
    Replies: 15
    Last Post: 12-21-2008, 07:20 AM
  2. [Q]Hide Password
    By Yuri in forum C++ Programming
    Replies: 14
    Last Post: 03-02-2006, 03:42 AM
  3. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 08:42 PM
  4. Password prompt in unix w/o \b
    By rafe in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 08:54 AM
  5. password
    By hammers6 in forum C Programming
    Replies: 1
    Last Post: 10-10-2001, 12:14 AM