hi
how can i convert all the keys for the user how enter for example his passwort
to char ********
hi
how can i convert all the keys for the user how enter for example his passwort
to char ********
It depends on your OS and compiler.
Do a board search, this is a common question.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Here's a Windows API version. Remember to include windows.h...
Code:char *getPass(char *szBuffer, size_t len) { size_t i; HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE); HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); DWORD dwOld, dwNumRead, dwNumWritten; if((hIn) && (hOut)) { if(GetConsoleMode(hIn,&dwOld)) { if(SetConsoleMode(hIn,ENABLE_PROCESSED_INPUT)) { for(i=0;i<len;i++) { if(ReadConsole(hIn,&szBuffer[i],1,&dwNumRead,NULL)) { if(szBuffer[i] == '\r') { WriteConsole(hOut,"\n",1,&dwNumWritten,NULL); szBuffer[i] = '\0'; break; } else WriteConsole(hOut,"*",1,&dwNumWritten,NULL); } else break; } SetConsoleMode(hIn,dwOld); return szBuffer; } } } return NULL; }
If using the WIN32 API, the edit control has a 'password' style ES_PASSWORD which will automatically replace text with asteriks.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
but what is the size_t ......................
size_t is a data type in the standard C library, inside stdio.h. If size_t is not defined in windows.h, which I believe it is, you can include it in your C++ program by including cstdio.
GIYF.
Last edited by MacGyver; 05-22-2007 at 07:26 AM.
I think size_t is associated with <cstddef>.
http://www.cplusplus.com/reference/c...ef/size_t.html
Edit: Actually the same site indicates that it's also in <cstdio>. I'm confused. Why is it guaranteed to be defined in more than one standard header file?
Edit: This is important to me since my code uses std::size_t a lot (and I always qualify it with std:: since I don't think it's guaranteed to be in the global namespace).
Last edited by robatino; 05-22-2007 at 08:51 AM.
This site names 4 header files where size_t is define:
- stdio.h
- stddef.h
- stdlib.h
- string.h
The date type is important for strings, as well as malloc() and other functions, so I guess they chose the route of defining it quite a few times as opposed to just keeping it in one header file that all the others would be dependent upon.