Hide User Input in FORTRAN 95: Solve Password Problem

  • Context: Fortran 
  • Thread starter Thread starter dawilso9
  • Start date Start date
  • Tags Tags
    Fortran
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
dawilso9
Messages
1
Reaction score
0
This might be a stupid question but my TAs in my lab could not answer it so I thought I would try to ask it here. What I want to do is for the user to enter some string of characters for something such as a password and for the input not to show up on the screen or for it to be replaced by something else so someone else cannot see what they previously entered.

Here is what I am asking:

Password: (User enters something)

What I want it to show as it is entered:

Password: (blank) or *********

I hope this is possible I have attempted to find the answer in my book and by googling it but to no avail. Thank you for any help you can provide.
 
Physics news on Phys.org
This is not part of "standard" Fortran (or any other language).

You need to call some routines that are part of your computer's operating system, or from a GUI (Graphical user interface) library, to do this.

Probably the "lowest level" way to do it would be code that does something like this:

do while (.true.)

call a routine to read a single keystroke, without the user having to press return, and without displaying anything on the screen

if the keystroke was "return", exit the loop
else store the character in a string, and display a * on the screen.
endinf
enddo

"Real" code to do this would be more complicated, because you need to handle what happens if the user pressed say a function key instread of a letter or number, what to do if the user presses the backspace key, etc, etc. A GUI library would probably include a routine that handles all this low-level stuff and just returns you the string.

Actually, in a really secure system, the GUI routine would not even return you the string that was typed, but an encrypted representation of it. You could pass the encrypted string to another routine to check if the password is valid, without your program ever being able to "see" what the real password was and "steal" it.