Thread: Password Asterisks

  1. #1
    Unregistered
    Guest

    Question Password Asterisks

    I am writing a Visual C++ program that executes from the command line that requires the user to input a password. How do I get the password to show up as asterisks instead of plain text as the user is typing it in?

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    read the threads on the faq board. and/or search these boards for password or similar because we have done this loads of times.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    0x01
    Join Date
    Sep 2001
    Posts
    88

    ...

    Code:
    #include "stdio.h"
    #include "conio.h"
    
    #define TRUE   1
    #define ENTER  0x0D  // Enter Key
    int main()
    {
    	// Yeah, yeah, i know = { NULL } isn't good to use
    	char str[80] = { NULL };
    	int  idx = 0;
    	printf("\n\n Type your life away\n ---");
    	printf("\n Input [hidden] : ");
    
    	while(TRUE)
    	{
    		char ch = getch();
    
    		if(ch == ENTER)
    			break;
    		else
    			putchar('*');
    
    		str[idx] = ch; idx++;
    	}
    	
    	printf("\n You entered    : %s\n\n", str);
    
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [Q]Hide Password
    By Yuri in forum C++ Programming
    Replies: 14
    Last Post: 03-02-2006, 03:42 AM
  2. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 08:42 PM
  3. how to enter a password with asterisks
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-06-2001, 12:38 PM
  4. password
    By hammers6 in forum C Programming
    Replies: 1
    Last Post: 10-10-2001, 12:14 AM
  5. Replies: 1
    Last Post: 09-01-2001, 10:33 AM