Here is my code that i am working on. Upon running the exe, it asks the user for a temporary password. After that, the screen saver pops up. Upon exiting the screen saver, the console will ask you for the temporary pass that you entered in order to renable the desktop.

So my question is, everything is compiling fine with no errors or warnings, but when i run the program i have a few problems. Everything works up to when the console asks for the password again to initialize the desktop, instead of attempting to verify the correct password, the program just ends.

#include <windows.h>
#include <iostream>
#include <winable.h>

using namespace std;

int rePass(0);  //first password
int rePassb(1); //password to compare

int main()
    cout << "Set Recovery pass: ";
    cin >> rePass;
    SendMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0); //Start screen saver
    //Saftey precaution to prevent instant screen saver disable by accedental mouse movement
    //Sloppy idle process until screen saver is disabled
       while(SC_SCREENSAVE == 1);
    EnableWindow(GetDesktopWindow(), 0); //Deactivate desktop
    //Tests if the intial password that was set matches the new password entered in order to enable desktop
        cout << "Enter Recovery Pass: ";
        cin >> rePassb;
            if(rePassb == rePass)
                 cout << "Re-Enabling Windows...";
                 EnableWindow(GetDesktopWindow(), 1); //Enable desktop if password was entered sucessfully
                cout << "Incorrect Password..." << endl << "Enter Recovery Pass: ";
                goto PassCheck; //Sends user back up to initial password entry
        return 0;
9 Years
Discussion Span
Last Post by Comatose

> int rePass(0); //first password
Most passwords are strings, not int's

> goto PassCheck;
Use a while loop.


as long as they compare correctly it shouldn't matter correct? Or will it affect my program in an odd way?


Well if your passwords are like 1234, then not a problem.

But try typing "opensesame", and you're in trouble.


SC_SCREENSAVE is a windows message.... it's a constant. A constant hex value (0XF140) and will never be 1. So your do loop will only run once, no matter what. If it where a while loop instead, the system("pause"); would never run, because the test condition would happen first.... I mean to say SC_SCREENSAVE doesn't tell you if the screensaver is on or not... it's just used by windows to tell the system to trigger the screensaver. Also, system("pause") is usually frowned upon, because it's not really portable, and requires a call to (I think) the kernel. cin.ignore(); would probably do the trick. Goto's.... while they are perfectly code legal, they are 90% unacceptable. They lead to "Spaghetti Code" where the line of execution keeps jumping around (this was required in asm.... jne :|). There are usually ways to avoid using goto's, and it's usually a good idea to avoid them (gotos). The enablewindow call (the call to disable the desktop) doesn't actually disable it. I can still work with it as though nothing had happened. This actually works to lock the desktop, but none of the opened windows or taskbar/start button: EnableWindow(FindWindowEx(FindWindow("Progman", NULL), HWND(0), "ShellDll_DefView", NULL), FALSE); So... you may have to do something similar to block the taskbar/startbutton and something to hide any open windows.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.