Hi guys, just wondering how you would set a window for how long you have to enter a password, thanks!
Hi guys, just wondering how you would set a window for how long you have to enter a password, thanks!
Your gonna have to be more specific than that. It is a bit difficult to tell exactly what you are trying to do or what in particular you are having problems with.
Cheers
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
If you mean to only allow the user to type in their password for a certain amount of time, look in to the SetTimer win32 function.
http://msdn.microsoft.com/library/de...s/settimer.asp
yes i want to let the user only have a certain amount of time to enter the password, i think ive seen a way to do it with Sleep(). Any ideas?
Assuming you're doing a windows GUI application, read jverkoey's link.
If you're doing a console application, you can use the nonstandard kbhit() which is defined in conio.h to check if a key has been pressed already, inputting the next character of the password if a key has been pressed and then check if it's correct.. etc. Put it in a loop, and on each iteration of the loop check if the time has elapsed. You can use GetTickCount() if you have <windows.h> included to find how long the system has been running in milliseconds, otherwise use the functions in <ctime>. An alternative to kbhit() that has been suggested by Anonytmouse in the past is to get a handle to the console input using GetStdHandle() and checking if input is waiting using WaitForSingleObject().
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Hi Guys, I went with the GetTickCount() approach. I need one minor bit of help though. It lets you enter the password for as long as you want. I know the problem and that is that the cin.getline() command has a cin.ignore() function built in anyone know how to get it out?
**This is just a prototype program dont worry about how the password is hardcoded into the programCode:#include <iostream> #include <windows.h> using namespace std; int main() { char password[25]; int x=(GetTickCount()+3000); while(GetTickCount()<x) { cout<<"Password: "; cin.getline(password, 25); } if(GetTickCount() >= x) { cout<<"DONE!"; } if(strcmp(password,"password")==0) { cout<<"\nCorrect!"; } else{ cout<<"\nWrong!"; } cin.get(); return 0; }
Something like that should work.Code:DWORD start = GetTickCount(); std::string pwd; cout << "Password: "; while(GetTickCount() - start < 10000) //10 seconds { if(kbhit()) pwd += (char)getch(); }
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
It wont compile, it says that kbhit() and getch() are undefined, that means the Header file is missing right? What header file is it under?
PS- What is a DWORD?
PSS- Any other ways?
Last edited by Junior89; 01-12-2005 at 09:00 PM.
kbhit() and getch() are in <conio.h>. You might not have it, since it isn't standard. Alternatively, you could write your own kbhit() function:
The functions I used in that come from <windows.h>, which it seems you do have.Code:bool kbhit() { HANDLE h = GetStdHandle(STD_INPUT_HANDLE); return (WaitForSingleObject(h, 0) == WAIT_OBJECT_0); }
**EDIT**
DWORD stands for 'double word', and is just a microsoft typedef for unsigned long. The function GetTickCount() returns a value of type DWORD, so for the sake of being absolutely sure that everything will be compatible (on the offchance that MS decides to make DWORD something else in the future), we store the result in a DWORD instead of unsigned long.
Last edited by Hunter2; 01-12-2005 at 09:26 PM.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.