Created
December 22, 2014 18:32
-
-
Save pmbuko/02c5a016b302135e1410 to your computer and use it in GitHub Desktop.
Revisions
-
pmbuko created this gist
Dec 22, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,135 @@ #!/usr/bin/python # # Simple python example of a Pashua password prompt window for changing passwords. # It prompts for the current password, new password, and new password verification. # It does the verification and redisplays the prompt with feedback if the current or # new passwords do not match. # # THIS WILL NOT ACTUALLY CHANGE PASSWORDS. I created this as an example of how you can # design Pashua dialogs and work with their output. # # For easiest testing, you should have the Pashua.py connector and Pashua.app # in the same directory as this script. # # The current password is 'password'. import sys import Pashua password = 'password' bad_current = False new_mismatch = False def passDialog(): '''Configures the Pashua dialog box for password prompt. Returns current, new, and verify passwords as strings''' if bad_current: f0 = 'Your password was incorrect. Please try again.' elif new_mismatch: f0 = 'Your passwords did not match. Please try again.' else: f0 = 'Change your password using the fields below.' f1 = 'Current Password:' f2 = 'New Password:' f3 = 'Verify:' # Dialog box configuration conf = ''' # Window *.title = Change Password *.floating = 1 # Feedback message msg.type = text msg.text = %s msg.width = 375 msg.x = 0 msg.y = 150 # Current text cmsg.type = text cmsg.text = %s cmsg.x = 1 cmsg.y = 112 # Current Password field cpsw.type = password cpsw.mandatory = 1 cpsw.width = 260 cpsw.x = 116 cpsw.y = 110 # New text nmsg.type = text nmsg.text = %s nmsg.x = 18 nmsg.y = 82 # New Password field npsw.type = password npsw.mandatory = 1 npsw.width = 260 npsw.x = 116 npsw.y = 80 # Verify text vmsg.type = text vmsg.text = %s vmsg.x = 72 vmsg.y = 52 # Verify Password field vpsw.type = password vpsw.mandatory = 1 vpsw.width = 260 vpsw.x = 116 vpsw.y = 50 # Default button db.type = defaultbutton db.label = OK # Cancel button cb.type = cancelbutton cb.label = Cancel ''' % (f0, f1, f2, f3) # 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['cpsw'], dialog['npsw'], dialog['vpsw'] def changePass(): global bad_current, new_mismatch '''Spawns a password prompt box and checks if passwords are correct/matching. If current password is incorrect or new passwords do not match then the prompt will reappear with appropriate feedback.''' successful = False while not successful: cpsw, npsw, vpsw, = passDialog() if cpsw == password: if npsw == vpsw: print 'Your password would have been changed.' successful = True else: bad_current = False new_mismatch = True else: bad_current = True new_mismatch = False def main(): changePass() if __name__ == '__main__': main()