• Welcome to Computer Association of SIUE - Forums.
 

password masking/hiding in c++

Started by JR, 2006-03-20T13:18:26-06:00 (Monday)

Previous topic - Next topic

JR



who knows how to show asterisks instead of the user's input in c++ ??

someone said something a/b masking or turning off echo ???

JR
Retired President of CAOS

Peter Motyka


const int passwdLength = 16;
char passwd [passwdLength];

for(int i=0; i <= passwdLength; i++)
{
    passwd[i] = getch();
    if (passwd[i] == 13) break;
    putch('*');
}


Needs some error handling/checking, but you get the idea...
SIUE CS Alumni 2002
Grad Student, Regis University
Senior Engineer, Ping Identity
http://motyka.org

JR


well, if 'getch()' == cin.get()  then thats not what im lookin for b/c the user still has to type (and the console is displaying what they are typing) and then hit enter before anything happens.

really, im looking for a trigger that something has been typed (one char). if i can get to that point, i can clear it and display *.


OR even easier, somehow turn off the user display for that statement....is it called echo ??

JR





Retired President of CAOS

Jerry

In C programs we used to use curses.h which defined an echo() and noecho(). These controlled whether a character that was typed in was displayed by getch().

"Make a Little Bird House in Your Soul" - TMBG...

JR


aaahhhh. that would explain me having no idea what getch() was. thanks dr. w

JR
Retired President of CAOS

Peter Motyka

Did you try compliling/running the code I posted?  It does exactly what you are describing as I tested it before posting.  BTW, my environment was Visual Studio 2003 on Windows XP.  I'd be curious if you had different results on a same/different platform.

SIUE CS Alumni 2002
Grad Student, Regis University
Senior Engineer, Ping Identity
http://motyka.org

Geoff Schreiber

You have to include the conio.h library in vc++ to get getch and putch...  Both of these commands disable echo by bypassing the input buffer.  getchar and putchar enable echo.


#include
int main()
{
const int passwdLength = 16;
char passwd [passwdLength];

for(int i=0; i <= passwdLength; i++)
{

passwd[i] = getch();
if (passwd[i] == 13) break;
putch('*');
}


return 0;
}
~~~~~~~~~~~~~~~~~~~
Geoff Schreiber
Project Engineer
FASTechnology Group

JR

sweet. conio.h did it. very cool. thanks guys


JR
Retired President of CAOS

Kaitlyn Schmidt

This IS very cool!!! Thanks for the code! I'm going to go play with it some more. :-D
Kaitlyn Schmidt
Senior, Computer Science
Former President of CAOS