delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/03/06/07:47:20

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
Message-id: <fc.000f77f3001f29583b9aca00e8ae905a.1f29a9@bni.mg>
Date: Wed, 06 Mar 2002 15:42:36 +0300
Subject: Re: password and masking
To: djgpp AT delorie DOT com
Cc: djgpp AT delorie DOT com
From: "NirinaMichel Ratoandromanana/DS-INFO" <n DOT ratoandromanana AT bni DOT mg>
References: <a64q59$psf$1 AT iac5 DOT navix DOT net>
In-Reply-To: <a64q59$psf$1@iac5.navix.net>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

Hi,
I used this code hacked from the source of FreeBSD:

unsigned char *getpwd (char prompt[], char *password)
{
	unsigned char *p = password;
	int c;
	printf ("%s", prompt);
	while (1)
	{
		c = getch();	//get char without echo, see getch vs. getche
		printf ("*");
		// terminate on end of line or file ^j, ^m, ^d, ^z
		if (c == '\r' || c == '\n' || c == '\004' || c == '\032')
			break;
		if (c == '\b')
		{
			p--;
//to get back and erase the previous * and get back again
			printf ("\0x1B \0x1B");
			continue;
		}
		*p++ = c;
	}
	*p = '\0';
	printf ("\n");
	return p;
}

You may get some warning messages but why worry, it works.

Nirina.

>I am wanting to (for lack of a better word) mask a password for a login as
>the user types the password.  For instance much like Linux displays
>nothing
>when a password is entered upon an attempted login.
>
>Well, in this specific case I am using fgets to get the password
>information
>but of course that does me no good until enter has been pressed.  What I
>was
>wanting to mask the password with was, "*"  (asterisks) much like many
>other
>logins in other OSs and the old BBSs used to do.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019