LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Prevent Terminal Echo Using Python (for Passwords) (https://www.linuxquestions.org/questions/programming-9/prevent-terminal-echo-using-python-for-passwords-340319/)

taylor_venable 07-05-2005 03:13 PM

Prevent Terminal Echo Using Python (for Passwords)
 
I have a Python program that gets a password from the user in order to log in to an ftp server using an ftplib.FTP() object. The program runs off the command line; and the problem is that the password is in plain view when typed in. Is there any way to 'cloak' the text being typed in, i.e. to prevent the keyboard input from being echoed to the terminal? (Like the behavior in ssh, for example.) I'm thinking maybe the readline module would allow me to do that, but I don't know how specifically. Thanks!

david_ross 07-05-2005 03:20 PM

I'm not sure if there is a pure python method but you could just make a system call before and after:
# Disable local echo
stty -echo
# Ask for password here
# Enable local echo
stty echo

taylor_venable 07-05-2005 04:53 PM

It Works!
 
Great! I didn't know about that command, but it sure does the trick. And it's much simpler than the curses module I've been wrangling with for the last hour. Thanks a lot!

vharishankar 07-05-2005 09:39 PM

curses is quite easy. I learnt it in a couple of hours to do a simple program.

It might be worth learning if you seek to do more complicated console applications.

taylor_venable 07-05-2005 11:52 PM

Just One Of Those Silly Mistakes...
 
I turned back to my curses problem after writing the os.system() call into my script, and suddenly realised why everything was going so totally wrong with it. I had made the script executable and was merely running it from the command line (i.e. "$ ./programs/python/test_curses.py"), but I didn't have a "#!/usr/bin/env python" (or any other hash-bang line) at the beginning of the file. And here I wondered why it just suddenly started dumping errors in a non-Python style. Just one of those silly programming mistakes, you know? So I ended up and played around with it for the rest of the evening and I think I have an ok handle on curses now. You're right, it isn't bad at all. If anyone's curious, the result (such as it is right now) is on my website, or more specifically: http://mysite.verizon.net/taylor_ven...ebpublish.html. Thanks again to both of you!


All times are GMT -5. The time now is 03:09 PM.