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.
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 the
main()function, and the variables we'll need. The struct named
termiosis a special...