Masking user input (password)

Reply

Join Date: May 2007
Posts: 2
Reputation: kavaas is an unknown quantity at this point 
Solved Threads: 0
kavaas kavaas is offline Offline
Newbie Poster

Re: how to create a password and change the password?

 
0
  #1
May 7th, 2007
i have ceated a file in C. i have to give the login security. i already gave the user name & password. but when i type the password the letters are visible how to hide the letters
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: how to create a password and change the password?

 
0
  #2
May 7th, 2007
What operating system are you on?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 2
Reputation: kavaas is an unknown quantity at this point 
Solved Threads: 0
kavaas kavaas is offline Offline
Newbie Poster

Re: how to create a password and change the password?

 
0
  #3
May 9th, 2007
Originally Posted by iamthwee View Post
What operating system are you on?
windows xp
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 275
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: how to create a password and change the password?

 
0
  #4
May 9th, 2007
There is no standard way to do that
If you want to win, you must not loose (Alan Ford)
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 136
Reputation: dr4g is an unknown quantity at this point 
Solved Threads: 5
dr4g's Avatar
dr4g dr4g is offline Offline
Junior Poster

Re: Masking user input (password)

 
0
  #5
May 9th, 2007
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.
GardCMS :: Open Source CMS :: Gardcms.org
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Masking user input (password)

 
0
  #6
May 9th, 2007
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...

  1. #include <stdio.h>
  2. #include <termios.h>
  3. #include <unistd.h>
  4. #include <ctype.h>
  5.  
  6. int mygetch ( void )
  7. {
  8. int ch;
  9. struct termios oldt, newt;
  10.  
  11. tcgetattr ( STDIN_FILENO, &oldt );
  12. newt = oldt;
  13. newt.c_lflag &= ~( ICANON | ECHO );
  14. tcsetattr ( STDIN_FILENO, TCSANOW, &newt );
  15. ch = getchar();
  16. tcsetattr ( STDIN_FILENO, TCSANOW, &oldt );
  17.  
  18. return ch;
  19. }
  20.  
  21. int main()
  22. {
  23.  
  24. int ch;
  25. char pword[BUFSIZ];
  26. int i = 0;
  27.  
  28. puts ("Enter your password");
  29. fflush(stdout);
  30.  
  31. while ((ch = mygetch()) != EOF
  32. && ch != '\n'
  33. && ch != '\r'
  34. && i < sizeof(pword) - 1)
  35. {
  36. if (ch == '\b' && i > 0)
  37. {
  38. printf("\b \b");
  39. fflush(stdout);
  40. i--;
  41. pword[i] = '\0';
  42. }
  43. else if (isalnum(ch))
  44. {
  45. putchar('*');
  46. pword[i++] = (char)ch;
  47. }
  48. }
  49.  
  50. pword[i] = '\0';
  51.  
  52. printf ("\nYou entered >%s<", pword);
  53.  
  54. return 0;
  55. }
Although the backspace don't work, might be a way round that.
Last edited by iamthwee; May 9th, 2007 at 2:55 pm.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Masking user input (password)

 
0
  #7
May 9th, 2007
hmmm it would appear

if (ch == 0x7f && i > 0) 
    {
      printf("\b \b");
      fflush(stdout);
      i--;
      pword[i] = '\0';
    }
Allows the backspace to be recognised but I'm not sure how reliable it is?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC