[Tutor] getpass

alan.gauld@bt.com alan.gauld@bt.com
Fri, 19 Jan 2001 17:25:59 -0000


> >>> import getpass
> >>> name = getpass.getpass('Type your name: ')
> Warning: Problem with getpass. Passwords may be echoed.
> Type your name: Rumpelstitskin
> >>>

FWIW I get the same result but without the warning on 
Solaris in Python 1.5.1

the docstring says:
>>> import getpass
>>> print getpass.__doc__
Utilities to get a password and/or the current user name.
 
getpass(prompt) - prompt for a password, with echo turned off
getuser() - get the user name from the environment or password database
 
Authors: Piers Lauder (original)
         Guido van Rossum (Windows support and cleanup)
 
>>> getpass.getpass('->')
->goo
'goo'
>>>

Clearly it echos the password. On NT4 it works as described
in the docstring...

Wierd. Lets take a lok at the code in getpass.py...

Aha! On windows it uses the getch() function from msvcrt
On unix it uses termios stuff to control the terminal but 
if import termios fails then it uses a default function which 
just calls _raw_input()

This in turn just uses sys.stdin.readline() which by default 
echos input.

This implies either the import or the termios calls are failing 
in both of our setups, now the question is why?! 

Back to the >>> prompt...

>>> import termios
Traceback (innermost last):
  File "<stdin>", line 1, in ?
ImportError: No module named termios
>>>

So that's why. But why is termios missing when getpass is 
there? And where do I get a valid termios module?

And for that I have no answer... anyone else have an idea?

Alan g.