Skip to content

Instantly share code, notes, and snippets.

@pmbuko
Last active August 29, 2015 14:11
Show Gist options
  • Save pmbuko/f140568a47117c2941f5 to your computer and use it in GitHub Desktop.
Save pmbuko/f140568a47117c2941f5 to your computer and use it in GitHub Desktop.
Simple python example of a Pashua password prompt dialog with a checkbox to save the password. Requires Pashua.app and the Pashua.py connector in the same path.
#!/usr/bin/python
#
# Simple python example of a Pashua password prompt window with a checkbox
# for saving the password to the keychain. None of it is wired up to
# actually function. It's just an example of what you can do.
#
# For easiest testing, you should have the Pashua.py connector and Pashua.app
# in the same directory as this script.
#
# The test password is 'password'.
import sys
import Pashua
ticket_id = '[email protected]'
def passDialog(ticket_id, retry):
'''Configures the Pashua dialog box for password prompt. Returns
password as string and save checkbox value as 0 or 1.'''
message = 'Ticket for %s expired. Enter your password to renew:' % ticket_id
if retry: message = 'Your password was incorrect. Please try again:'
# Dialog box configuration
conf = '''
# Window
*.title = Kerberos Ticket Renewal
*.floating = 1
# Message
msg.type = text
msg.text = %s
msg.x = 80
msg.y = 110
# Password field
psw.type = password
psw.mandatory = 1
psw.width = 280
psw.x = 82
psw.y = 70
# Save checkbox
save.type = checkbox
save.label = Remember this password in my keychain
save.x = 80
save.y = 45
# Default button
db.type = defaultbutton
db.label = OK
# Cancel button
cb.type = cancelbutton
cb.label = Cancel
''' % message
# Open dialog and get input
dialog = Pashua.run(conf)
# Check for Cancel before return
if dialog['cb'] == '1':
print('User canceled.')
sys.exit(0)
return dialog['psw'], dialog['save']
def getPass(retry = False):
'''Spawns a password prompt box and checks if password is correct. Calls itself
with a different message for retries.'''
psw, save = passDialog(ticket_id, retry)
if psw == 'password':
if save == '1':
print 'Password is \'%s\'. Will save to keychain.' % psw
else:
print 'Password is \'%s\'. Will not save.' % psw
else:
getPass(True)
def main():
getPass()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment