Reputation: 17829
So I don't know if I am missing some documentation, but I have two issues with getpass
.
I can't seem to save the password
It echos the password after
>>> pass = getpass.getpass()
File "<stdin>", line 1
pass = getpass.getpass()
^
SyntaxError: invalid syntax
>>> getpass.getpass()
Password:
'ryan'
Am I doing something wrong?
Upvotes: 1
Views: 1478
Reputation: 113930
Pass is a python keyword, meaning that you can't assign variables to it. Try psswd
or something similar instead.
Upvotes: 7
Reputation: 414079
1) I can't seem to save the password.
>>> pass = getpass.getpass()
...
SyntaxError: invalid syntax
The syntax error is expected:
>>> import keyword
>>> keyword.kwlist
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
>>> 'pass' in keyword.kwlist
True
You can't assign to a keyword except to those that are active only after corresponding __future__
import.
2) It echos the password after:
>>> getpass.getpass()
Password:
'most bear metal bright'
You see repr()
of the returned value from getpass()
function. Assign it to a variable:
>>> cleartext = getpass.getpass()
Password:
>>> compare_hash(crypt.crypt(cleartext, hashed), hashed)
False
Upvotes: 0