Link to home
Start Free TrialLog in
Avatar of urif
urif

asked on

non echoed passwords

hi, part of the program that i am writing needs to get  a password from the user.
i've been trying to come up with a way to not echo the password as the user types, much like the unix login or other command like programs like gpg, but sor far i only get exceptions.

is there a standard way to do this?

if possible i need a solution that migth work in both win32 and linux patforms.

thanks, any help is appreciated.
Avatar of van_dy
van_dy

on linux you have
getpass() call. take a look at its man page.
Avatar of urif

ASKER

from the man page

DESCRIPTION
       This function is obsolete. Do not use it.
Avatar of sunnycoder
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i am not sure if readpassphrase() will be present on linux, but
you can check that out too. Plus i doubt if the method will
be portable to windows. to set the terminal echoing off, getpass()
issues ioctl() or tcsetattr().

hope this helps
Avatar of urif

ASKER

thanks.

everywhere i look is says don't use getpass()...
any idea why?

in anycase what about win32?
Hmm, there are a few reasons for it

 most of the implementations of getpass usually return the password
     in a static buffer stored in the function. so subsequent calls to getpass()
     will overwrite the previously read password. U may need to
     copy the newly read password in your own buffer if u are going to use it
Hi urif,

there's a function getch() in "conio.h" (MSVC60) which returns a character without echoing it to the console. you'll have to print the '*' by youself then.

Cheers! S.
Avatar of urif

ASKER

thanks everyone