Cant solve what is wrong

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2008
Posts: 111
Reputation: clutchkiller is an unknown quantity at this point 
Solved Threads: 1
clutchkiller's Avatar
clutchkiller clutchkiller is offline Offline
Junior Poster

Cant solve what is wrong

 
0
  #1
Jan 3rd, 2009
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.

  1. #include <windows.h>
  2. #include <iostream>
  3. #include <winable.h>
  4.  
  5. using namespace std;
  6.  
  7. int rePass(0); //first password
  8. int rePassb(1); //password to compare
  9.  
  10. int main()
  11. {
  12. cout << "Set Recovery pass: ";
  13. cin >> rePass;
  14. cin.get();
  15. SendMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0); //Start screen saver
  16.  
  17. //Saftey precaution to prevent instant screen saver disable by accedental mouse movement
  18. BlockInput(1);
  19. Sleep(2000);
  20. BlockInput(0);
  21.  
  22. //Sloppy idle process until screen saver is disabled
  23. do{
  24. system("PAUSE");
  25. }
  26. while(SC_SCREENSAVE == 1);
  27.  
  28. Sleep(2000);
  29. EnableWindow(GetDesktopWindow(), 0); //Deactivate desktop
  30.  
  31. //Tests if the intial password that was set matches the new password entered in order to enable desktop
  32. PassCheck:
  33.  
  34. cout << "Enter Recovery Pass: ";
  35. cin >> rePassb;
  36.  
  37. if(rePassb == rePass)
  38. {
  39. cout << "Re-Enabling Windows...";
  40. EnableWindow(GetDesktopWindow(), 1); //Enable desktop if password was entered sucessfully
  41. Sleep(2000);
  42. }
  43.  
  44. else
  45. {
  46. cout << "Incorrect Password..." << endl << "Enter Recovery Pass: ";
  47. goto PassCheck; //Sends user back up to initial password entry
  48. }
  49.  
  50. cin.get();
  51. return 0;
  52. }
>That confuses me =(
Get used to it. Good programmers are in a constant state of confusion.
>Looks like i have some quasi specifics to investigate! Up Up And AWAY!
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Cant solve what is wrong

 
0
  #2
Jan 3rd, 2009
> int rePass(0); //first password
Most passwords are strings, not int's

> goto PassCheck;
Use a while loop.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 111
Reputation: clutchkiller is an unknown quantity at this point 
Solved Threads: 1
clutchkiller's Avatar
clutchkiller clutchkiller is offline Offline
Junior Poster

Re: Cant solve what is wrong

 
0
  #3
Jan 3rd, 2009
as long as they compare correctly it shouldn't matter correct? Or will it affect my program in an odd way?
>That confuses me =(
Get used to it. Good programmers are in a constant state of confusion.
>Looks like i have some quasi specifics to investigate! Up Up And AWAY!
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Cant solve what is wrong

 
0
  #4
Jan 3rd, 2009
Well if your passwords are like 1234, then not a problem.

But try typing "opensesame", and you're in trouble.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Cant solve what is wrong

 
0
  #5
Jan 3rd, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC