Skip to content

Instantly share code, notes, and snippets.

@packetforger
Created March 26, 2014 10:05
Show Gist options
  • Save packetforger/9780105 to your computer and use it in GitHub Desktop.
Save packetforger/9780105 to your computer and use it in GitHub Desktop.
getpass
#!/usr/bin/python2
"""
Example use of "getpass" in python to accept user input
of sensitive information such as passwords without echoing
them back to the screen.
Example Run:
$ python test.py
Example Getpass Use Script
Input Your Credentials (password will not be echoed)
USER: this is a test username
PASS:
Printing Your Credentials
{+} USER: this is a test username
{+} PASS: this is a test password
$
As you can see, the "password" input did not echo back
my input. This is useful as it prevents against shoulder
surfers and such evil creatures (well, assuming they dont
just look at the bloody keys you are pressing!!)
- infodox
"""
import getpass # import getpass module
def main():
print "Example Getpass Use Script"
print "Input Your Credentials (password will not be echoed)"
username = raw_input("USER: ") # doesnt matter if we echo username so use raw_input()
password = getpass.getpass("PASS: ") # use getpass to get passwd without echoing it back
print "Printing Your Credentials"
print "{+} USER: %s" %(username) # print username
print "{+} PASS: %s" %(password) # print the password
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment