summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-07-28 19:28:43 (GMT)
committerGuido van Rossum <guido@python.org>1998-07-28 19:28:43 (GMT)
commit1a7bab05e8667756cf30d07ff86f97375fd6168b (patch)
treec57577408dbfb709c14ec76684cb7c46fcf6e757
parentec8c8c2ef2cac83a12b249c4e6ba4c62c018bfdc (diff)
downloadcpython-1a7bab05e8667756cf30d07ff86f97375fd6168b.zip
cpython-1a7bab05e8667756cf30d07ff86f97375fd6168b.tar.gz
cpython-1a7bab05e8667756cf30d07ff86f97375fd6168b.tar.bz2
Don't use raw_input() to ask for the password; this puts the password
in the GNU readline history buffer which is not such a great idea.
-rw-r--r--Lib/getpass.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/getpass.py b/Lib/getpass.py
index d67240e..be7a2f9 100644
--- a/Lib/getpass.py
+++ b/Lib/getpass.py
@@ -36,7 +36,7 @@ def getpass(prompt='Password: '):
new[3] = new[3] & ~TERMIOS.ECHO # 3 == 'lflags'
try:
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new)
- passwd = raw_input(prompt)
+ passwd = _raw_input(prompt)
finally:
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old)
@@ -66,7 +66,22 @@ def win_getpass(prompt='Password: '):
def default_getpass(prompt='Password: '):
- return raw_input(prompt)
+ return _raw_input(prompt)
+
+
+def _raw_input(prompt=""):
+ # A raw_input() replacement that doesn't save the string in the
+ # GNU readline history.
+ import sys
+ prompt = str(prompt)
+ if prompt:
+ sys.stdout.write(prompt)
+ line = sys.stdin.readline()
+ if not line:
+ raise EOFError
+ if line[-1] == '\n':
+ line = line[:-1]
+ return line
def getuser():