import getpass

def login():
    user = eval(input('Username [%s]: ' % getpass.getuser()))
if not user:
    user = getpass.getuser()
pprompt = lambda : (getpass.getpass(), getpass.getpass('Retype password: '))
p1, p2 = pprompt()
while p1 != p2:
    print('Passwords do not match. Try again')
p1, p2 = pprompt()
return user, p1
Read password from stdin