943,547 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 9447
  • C RSS
May 7th, 2007
0

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

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kavaas is offline Offline
2 posts
since May 2007
May 7th, 2007
0

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

What operating system are you on?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
May 9th, 2007
0

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

Click to Expand / Collapse  Quote originally posted by iamthwee ...
What operating system are you on?
windows xp
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kavaas is offline Offline
2 posts
since May 2007
May 9th, 2007
0

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

There is no standard way to do that
Reputation Points: 251
Solved Threads: 29
Posting Whiz in Training
andor is offline Offline
274 posts
since Jun 2005
May 9th, 2007
0

Re: 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.
Reputation Points: 35
Solved Threads: 5
Junior Poster
dr4g is offline Offline
136 posts
since Apr 2007
May 9th, 2007
0

Re: Masking user input (password)

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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
May 9th, 2007
0

Re: Masking user input (password)

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?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Capitalize first char of every word in input string
Next Thread in C Forum Timeline: print sting using printf in main or functions?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC