Disabling echo for password prompts
To protect users' passwords from shoulder surfing, it's always best to hide what they type. The way to hide a password from being displayed is to disable echoing. In this recipe, we'll write a simple password program with echoing disabled.
Knowing how to disable echoing is key when writing programs that take some form of secret input, such as a password or a key.
Getting ready
For this recipe, you'll need the GCC compiler, the Make tool, and the generic Makefile.
How to do it…
In this recipe, we'll build a small program with a password prompt
- Since the code in this recipe will be rather long and some parts a bit arcane, I have split up the code into several steps. Note, however, that all code should go into a single file. Name the file
passprompt.c
. Let's start with theinclude
lines, themain()
function, and the variables we'll need. The struct namedterm
of typetermios
is a special...