Mask password input on stdin

This commit is contained in:
Michael Kropat 2014-06-06 17:07:30 -04:00
parent 242cadebc8
commit 5774205bc2
1 changed files with 11 additions and 2 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3
import sys, urllib.request, urllib.error
import sys, getpass, urllib.request, urllib.error
def mgmt(cmd, data=None):
req = urllib.request.Request('http://localhost:10222' + cmd, urllib.parse.urlencode(data).encode("utf8") if data else None)
@ -11,6 +11,15 @@ def mgmt(cmd, data=None):
sys.exit(1)
return response.read().decode('utf8')
def read_password():
first = getpass.getpass('password: ')
second = getpass.getpass(' (again): ')
while first != second:
print('Passwords not the same. Try again.')
first = getpass.getpass('password: ')
second = getpass.getpass(' (again): ')
return first
if len(sys.argv) < 2:
print("Usage: ")
print(" tools/mail.py user (lists users)")
@ -33,7 +42,7 @@ elif sys.argv[1] == "user" and sys.argv[2] in ("add", "password"):
email = input("email: ")
else:
email = sys.argv[3]
pw = input("password: ")
pw = read_password()
else:
email, pw = sys.argv[3:5]