| | |
Masking user input (password)
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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?
Views: 4934 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C
#include * .net append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft mqqueue mysql number oddnumber odf opensource overwrite owf pdf performance pointer pointers posix probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi






