Any method to mask the password that the user entered?

This is a discussion on Any method to mask the password that the user entered? within the C Programming forums, part of the General Programming Boards category; I am a college student and i received an assignment last week. I think i am able to complete the ...

  1. #1
    FCF
    FCF is offline
    Registered User FCF's Avatar
    Join Date
    Dec 2001
    Posts
    40

    Question Any method to mask the password that the user entered?

    I am a college student and i received an assignment last week. I think i am able to complete the assignment but in the password section, i think my program will be better if the password that the user entered will be masked by my program. My program needs the user to enter their IDs and passwords through the keyboard. My idea is : Any method to mask the password while the user is typing the password ? I afraid that someone will not understand my question... I mean if i press "9" on the keyboard then the "9" will appears on the monitor, but now i want to mask the "9" with anything such as the asterisk "*". Any suggestions ? Please mail to me fcheefatt@yahoo.com if you have any idea.

  2. #2
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744
    You can use a function to read the string that doesn't display the char on the screen and then echo a '*'

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main()
    {
    	char password[100];
    	int i=0;
    
    	do
    	{
    		password[i]=getch();
    		printf("*");
    		i++;
    	}
    	while(password[i-1]!='\r');
    	password[i-1]='\0';//remove the newline
    	printf("\n\n%s",password);
    	return 0;
    }
    hope it helps

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    16

    unix?

    If you're under *nix, you could try using readline(), although this might not be allowed.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Cannot be done with ANSI C. Check your compiler's BIOS functions, or keyboard functions. Basically, you want to just capture their key-presses. If you want to print something, say, asteriks, then you'll just have to add that to your function. Remember that by just capturing key-presses, you'll have to have special cases for <ENTER> and <BACKSPACE>
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. on method pointers and inheritance
    By BrownB in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2009, 07:50 PM
  2. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM
  3. Password program problem.
    By netboy in forum C Programming
    Replies: 3
    Last Post: 12-22-2001, 09:54 AM
  4. use user entered formula to calculate something
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 12-07-2001, 02:21 AM
  5. password
    By hammers6 in forum C Programming
    Replies: 1
    Last Post: 10-10-2001, 01:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21