• C

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.
urifAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

van_dyCommented:
on linux you have
getpass() call. take a look at its man page.
0
urifAuthor Commented:
from the man page

DESCRIPTION
       This function is obsolete. Do not use it.
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
van_dyCommented:
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
0
urifAuthor Commented:
thanks.

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

in anycase what about win32?
0
van_dyCommented:
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
0
skypalaeCommented:
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.
0
urifAuthor Commented:
thanks everyone
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.