How would one go about masking an input... Like when entering passwords and pins and such? Running Windows Vista, making a Console app. Thanks guys.
How would one go about masking an input... Like when entering passwords and pins and such? Running Windows Vista, making a Console app. Thanks guys.
You probably think you are the first who is asking this question...
Search forum for similar posts, read the answers, write your code and ask question about problems you encountered
For the start - read thsi http://faq.cprogramming.com/cgi-bin/...&id=1043284392
It explains how you can read an input before user press enter
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
I'm having some trouble using it. Here's my code:It gives me my error EVERY time. I don't know how to make it work. Any help? Thanks.Code:#include <iostream> #include <cstdlib> #include <windows.h> #include <winable.h> #include <string> #include <winuser.h> #include <stdio.h> #include <conio.h> #include <ctype.h> using namespace std; int main(int argc, char *argv[]) { int ch; int i = 0; char PROTECTEDLOL[12]; char password[90]; int SECRETANSWER; LOL: system("color fc"); system("cls"); puts ("What would you like to do?"); puts ("Enter password"); puts (" OR " ); puts ("Press [2] To Exit" ); fflush(stdout); while ((ch = getch()) != EOF && ch != '\n' && ch != '\r' && i < sizeof(PROTECTEDLOL) - 1) { if (ch == '\b' && i > 0) { printf("\b \b"); fflush(stdout); i--; PROTECTEDLOL[i] = '\0'; } else if (isalnum(ch)) { putchar('*'); PROTECTEDLOL[i++] = (char)ch; } } if (PROTECTEDLOL=="password") { puts ("Hi"); } else if (PROTECTEDLOL=="2") { cout<<endl<<endl<<"Bye"<<endl; Sleep(3000); return 0; } else { MessageBox(NULL, "Password is invalid", "Denied", 48 | 1); MessageBox(NULL, "Access is denied", "Denied", 48 | 1); goto LOL; } return 0; }
conio and getch are for Borland compilers
what compiler are you using?
what is the error?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Dev-C++,
And by 'my error' I'm refering to line 62, my 'else' statement.
I've looked in Dev-C++'s 'include' directory, and conio.h is in there.
Thanks to anyone that can help with my problem.
This compares pointers -> will never be trueCode:if (PROTECTEDLOL=="password")
use strcmp()
Kurt
more like
orCode:if ( strcmp(PROTECTEDLOL,"password") == 0 )
KurtCode:if ( !strcmp(PROTECTEDLOL,"password"))
Oh thankyou.
EDIT:
ERRORS:Code:#include <iostream> #include <cstdlib> #include <windows.h> #include <winable.h> #include <string> #include <winuser.h> #include <stdio.h> #include <conio.h> #include <ctype.h> using namespace std; int main(int argc, char *argv[]) { int ch; int i = 0; char PROTECTEDLOL[BUFSIZ]; char password[BUFSIZ]; int SECRETANSWER; LOL: system("color fc"); system("cls"); puts ("What would you like to do?"); puts ("Enter password"); puts (" OR " ); puts ("Press [2] To Exit" ); fflush(stdout); while ((ch = getch()) != EOF && ch != '\n' && ch != '\r' && i < sizeof(PROTECTEDLOL) - 1) { if (ch == '\b' && i > 0) { printf("\b \b"); fflush(stdout); i--; PROTECTEDLOL[i] = '\0'; } else if (isalnum(ch)) { putchar('x'); PROTECTEDLOL[i++] = (char)ch; } } if ( !strcmp(PROTECTEDLOL,"password")); { puts ("Hi"); } else if ( !strcmp(PROTECTEDLOL,"2")) { cout<<endl<<endl<<"Bye"<<endl; Sleep(3000); return 0; } else { MessageBox(NULL, "Password is invalid", "Denied", 48 | 1); MessageBox(NULL, "Access is denied", "Denied", 48 | 1); goto LOL; } return 0; }
Code:55 C:\Users\bradszy\Desktop\Untitled1.cpp expected primary-expression before "else" 55 C:\Users\bradszy\Desktop\Untitled1.cpp expected `;' before "else" 62 C:\Users\bradszy\Desktop\Untitled1.cpp expected primary-expression before "else" 62 C:\Users\bradszy\Desktop\Untitled1.cpp expected `;' before "else"
Last edited by bradszy; 02-23-2008 at 03:58 AM.
Code:if ( !strcmp(PROTECTEDLOL,"password")); <<-- remove that semicolon
Thanks Kurt, you're pretty good at this eh? Worked perfectly. Thanks again, it's really appreciated.
Another suggestion for you, in case you have time or is willing: http://cpwiki.sf.net/Indentation
Good luck.
I'm partial to this implementation - no particular reason
http://cboard.cprogramming.com/showp...94&postcount=5
gg