| | |
Masking user input (password)
![]() |
When you type characters into the console, its going to STDIN.
you're wanting to modify the character value coming from the keyboard.
There are Windows API functions available for this. off the top of my head i can't remember what they are. MSDN would be your best bet for this.
you're wanting to modify the character value coming from the keyboard.
There are Windows API functions available for this. off the top of my head i can't remember what they are. MSDN would be your best bet for this.
GardCMS :: Open Source CMS :: Gardcms.org
This is unportable... but you might be able to use...
http://faq.cprogramming.com/cgi-bin/...&id=1043284392
For other OS etc the following might also interest you...
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
From that the following seems to work in linux...
Although the backspace don't work, might be a way round that.
http://faq.cprogramming.com/cgi-bin/...&id=1043284392
For other OS etc the following might also interest you...
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
From that the following seems to work in linux...
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <termios.h> #include <unistd.h> #include <ctype.h> int mygetch ( void ) { int ch; struct termios oldt, newt; tcgetattr ( STDIN_FILENO, &oldt ); newt = oldt; newt.c_lflag &= ~( ICANON | ECHO ); tcsetattr ( STDIN_FILENO, TCSANOW, &newt ); ch = getchar(); tcsetattr ( STDIN_FILENO, TCSANOW, &oldt ); return ch; } int main() { int ch; char pword[BUFSIZ]; int i = 0; puts ("Enter your password"); fflush(stdout); while ((ch = mygetch()) != EOF && ch != '\n' && ch != '\r' && i < sizeof(pword) - 1) { if (ch == '\b' && i > 0) { printf("\b \b"); fflush(stdout); i--; pword[i] = '\0'; } else if (isalnum(ch)) { putchar('*'); pword[i++] = (char)ch; } } pword[i] = '\0'; printf ("\nYou entered >%s<", pword); return 0; }
Last edited by iamthwee; May 9th, 2007 at 2:55 pm.
*Voted best profile in the world*
![]() |
Similar Threads
- user input into a string (C++)
- Password Generator (Visual Basic 4 / 5 / 6)
- error checking of user input (C++)
- Help with comparing user input to a text file! (C++)
- Creating a GUI that accepts user input help (Java)
- Need Help With Error Checking User Input (C)
- filtering bad user input (Java)
Other Threads in the C Forum
- Previous Thread: win32 prob
- Next Thread: print sting using printf in main or functions?
| Thread Tools | Search this Thread |
#include * ansi array arrays asterisks binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile copypdffile creafecopyofanytypeoffileinc createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop function getlogicaldrivestrin givemetehcodez grade gtkwinlinux histogram homework i/o ide inches include infiniteloop input interest intmain() iso keyboard km license linked linkedlist linux list looping lowest matrix meter microsoft mysql number oddnumber open opendocumentformat openwebfoundation pdf pointer posix power probleminc process program programming pyramidusingturboccodes radix read recursion recv recvblocked research reversing scheduling segmentationfault send sequential single socket socketprogramming stack standard strchr string suggestions systemcall test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






