Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a7bab0

Browse files
committed
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.
1 parent ec8c8c2 commit 1a7bab0

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

Lib/getpass.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def getpass(prompt='Password: '):
3636
new[3] = new[3] & ~TERMIOS.ECHO # 3 == 'lflags'
3737
try:
3838
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new)
39-
passwd = raw_input(prompt)
39+
passwd = _raw_input(prompt)
4040
finally:
4141
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old)
4242

@@ -66,7 +66,22 @@ def win_getpass(prompt='Password: '):
6666

6767

6868
def default_getpass(prompt='Password: '):
69-
return raw_input(prompt)
69+
return _raw_input(prompt)
70+
71+
72+
def _raw_input(prompt=""):
73+
# A raw_input() replacement that doesn't save the string in the
74+
# GNU readline history.
75+
import sys
76+
prompt = str(prompt)
77+
if prompt:
78+
sys.stdout.write(prompt)
79+
line = sys.stdin.readline()
80+
if not line:
81+
raise EOFError
82+
if line[-1] == '\n':
83+
line = line[:-1]
84+
return line
7085

7186

7287
def getuser():

0 commit comments

Comments
 (0)