LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-05-2005, 03:13 PM   #1
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
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!
 
Old 07-05-2005, 03:20 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
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
 
Old 07-05-2005, 04:53 PM   #3
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Original Poster
Rep: Reputation: 43
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!
 
Old 07-05-2005, 09:39 PM   #4
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
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.
 
Old 07-05-2005, 11:52 PM   #5
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Original Poster
Rep: Reputation: 43
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!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I prevent echo eating spaces? essdeeay Linux - General 3 11-01-2005 03:11 PM
Python Terminal Gui Kedelfor Programming 2 10-24-2005 03:50 PM
Checking passwords and system clock in Python 1337 Twinkie Programming 9 10-31-2004 06:06 PM
Kphone echo (echo echo) scabies Linux - Software 0 10-18-2004 02:59 PM
behaviour of echo with ? (the question mark) in gnome-terminal fsbooks Programming 1 01-08-2004 12:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration