473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

silent raw_input for passwords

I need a password for a script and I would like to not have it stored in a
file or shown in a terminal.

"passphrase = raw_input()" still lets you see the input on the screen. Is
there a way to have it be hidden? It's my gpg passphrase, so I don't want
it anywhere except in my head.

If anyone's interested, I'm wrapping the command for the duplicity program
(incremental GPG encrypted backups to an FTP server;
http://www.nongnu.org/duplicity/):

===========================
#!/bin/env python

from ftplib import FTP
from os import popen

dirfile = '/usr/local/backups.txt'
dirs = file(dirfile).read().split('\n')

host = 'ftphost'
uname = 'ftpuname'
password = 'ftppass'

ftp = FTP(ftphost)
ftp.login(ftpuname,ftppass)
l=ftp.nlst()

for i,dir in enumerate(dirs):
if str(i+1) not in l:
print 'Directory "%s" is not on the FTP server.' % dir
print "Creating directory %d on server..." % (i+1)
ftp.mkd(str(i+1))
ftp.quit()

print "Starting duplicity synchronization ..."
print "Enter your passphrase:"
passphrase = raw_input()
passphrase = "PASSPHRASE=" + passphrase

for i in range(1,len(dirs)+1):
command = passphrase + ' duplicity ftp://'
command += ftpuname + '@' + ftphost + '/ "'
command += dirs[i-1] + '" ' + str(i)
print "Starting backup of directory %s" % dirs[i-1]
popen(command).read()

print "Done!"
--
Stephen
From here to there
and there to here,
funny things are everywhere. -- Dr Seuss

Jul 18 '05 #1
4 12630
On Fri, 30 Apr 2004 21:26:40 -0500,
Stephen Boulet <st********@spam.theboulets.net.please> wrote:
I need a password for a script and I would like to not have it
stored in a file or shown in a terminal. "passphrase = raw_input()" still lets you see the input on the
screen. Is there a way to have it be hidden? It's my gpg
passphrase, so I don't want it anywhere except in my head.


See the getpass module; it's part of the standard library.

Most GUI's have similar functionality.

HTH,,
Heather

--
Heather Coppersmith
That's not right; that's not even wrong. -- Wolfgang Pauli
Jul 18 '05 #2
Thanks!

Heather Coppersmith wrote:
On Fri, 30 Apr 2004 21:26:40 -0500,
Stephen Boulet <st********@spam.theboulets.net.please> wrote:
I need a password for a script and I would like to not have it
stored in a file or shown in a terminal.

"passphrase = raw_input()" still lets you see the input on the
screen. Is there a way to have it be hidden? It's my gpg
passphrase, so I don't want it anywhere except in my head.


See the getpass module; it's part of the standard library.

Most GUI's have similar functionality.

HTH,,
Heather


--
Stephen
From here to there
and there to here,
funny things are everywhere. -- Dr Seuss

Jul 18 '05 #3
Stephen Boulet <st********@spam.theboulets.net.please> wrote in message news:<B3********************@speakeasy.net>...
I need a password for a script and I would like to not have it stored in a
file or shown in a terminal.

"passphrase = raw_input()" still lets you see the input on the screen. Is
there a way to have it be hidden? It's my gpg passphrase, so I don't want
it anywhere except in my head.


There's probably an easier way, but you can use:

def input_password(echo=True):
chars = []
while True:
newChar = getch()
if newChar in '\r\n':
break
elif newChar in '\b\x7F':
if chars:
del chars[-1]
sys.stdout.write('\b')
else:
chars.append(newChar)
if echo:
sys.stdout.write('*')
return ''.join(chars)
Jul 18 '05 #4
On 2004-05-01, Dan Bishop <da*****@yahoo.com> wrote:
Stephen Boulet <st********@spam.theboulets.net.please> wrote in message news:<B3********************@speakeasy.net>...
I need a password for a script and I would like to not have it stored in a
file or shown in a terminal.

"passphrase = raw_input()" still lets you see the input on the screen. Is
there a way to have it be hidden? It's my gpg passphrase, so I don't want
it anywhere except in my head.


There's probably an easier way, but you can use:

def input_password(echo=True):
chars = []
while True:
newChar = getch()
if newChar in '\r\n':
break
elif newChar in '\b\x7F':
if chars:
del chars[-1]
sys.stdout.write('\b')
else:
chars.append(newChar)
if echo:
sys.stdout.write('*')
return ''.join(chars)


How is this different from getpass.getpass() ?

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: J. W. McCall | last post by:
I'm working on a MUD server and I have a thread that gets keyboard input so that you can enter commands from the command line while it's in its main server loop. Everything works fine except that...
0
by: dale | last post by:
Python newbie disclaimer on I am running an app with Tkinter screen in one thread and command-line input in another thread using raw_input(). First question - is this legal, should it run...
3
by: TThai | last post by:
Hi, I've created an application that uses crystal report in VB dotnet environment. I've created an MSI package to be installed on the client pc to make the crystal report to work. However, the...
1
by: JerryKreps | last post by:
Hi, folks -- I'm a Python pup. As you can see from the session copied at the end of this post, I have the latest version of Python, and I've been using the Editor-Shell of the latest version of...
21
by: planetthoughtful | last post by:
Hi All, As always, my posts come with a 'Warning: Newbie lies ahead!' disclaimer... I'm wondering if it's possible, using raw_input(), to provide a 'default' value with the prompt? I would...
17
by: Stuart McGraw | last post by:
In the announcement for Python-2.3 http://groups.google.com/group/comp.lang.python/msg/287e94d9fe25388d?hl=en it says "raw_input(): can now return Unicode objects". But I didn't see anything...
7
by: Mike Kent | last post by:
It's often useful for debugging to print something to stderr, and to route the error output to a file using '2>filename' on the command line. However, when I try that with a python script, all...
8
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples....
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.