omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    [Feature Request] Password to lock Pythonista App for Parental Control

    Pythonista
    6
    20
    9209
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • henryaukc
      henryaukc last edited by

      I try to write an authentication script and put it in 'site-packages' as pythonista_startup.py. But it is easily by-passed even I typed the wrong password, it gave me some time to press the stop button for the script in-between the validating process. Seems like this is not a possible method to lock the pythonista environment with password.

      from passlib.hash import pbkdf2_sha256
      import dialogs
      import os
      
      file = './.passwd'
      
      if not os.path.isfile(file):
      	p1 = None
      	p2 = 'password'
      
      	while p1 != p2:
      		p1 = dialogs.password_alert('Create a password:\nPleaes enter your password', hide_cancel_button=True)
      		
      		if len(p1) == 0:
      			dialogs.hud_alert('Password can\'t be empty!')
      			continue
      		p2 = dialogs.password_alert('Pleaes enter your password again to confirm', hide_cancel_button=True)
      	
      		if p1 != p2:
      			dialogs.hud_alert('The password you entered does not match. Try again')	
      		
      	hash = pbkdf2_sha256.encrypt(p1, rounds=200000, salt_size=16)
      	
      	with open(file, 'w+') as F:
      		F.write(hash)
      		
      	if os.path.isfile(file) and os.path.getsize(file) > 0:
      		dialogs.hud_alert('Your password has been saved successfully!')	
      	else:
      		dialogs.hud_alert('Error! Password has not been saved!')
      else:
      	p1 = None
      	trial = 0
      	success = False
      	
      	while not success: 
      		p1 = dialogs.password_alert('Pleaes enter your password', hide_cancel_button=True)
      		with open(file, 'r') as F:
      			hash = F.read()
      		success = pbkdf2_sha256.verify(p1, hash)
      		if success:
      			dialogs.hud_alert('Login Success!')
      		else:
      			dialogs.hud_alert('Login Failed! Try again!')
      			trial += 1
      
      1 Reply Last reply Reply Quote 0
      • henryaukc
        henryaukc last edited by

        Any method can be called to quit Pythonista if too many failed attempt?

        1 Reply Last reply Reply Quote 0
        • JonB
          JonB last edited by

          you should be able to wrap the script in a try/except KeyboardInterrupt and then force quit if a KeyboardInterrupt happens.
          you can use

          import objc_util
          ObjCInstance(1)
          

          to force a crash.

          Alternatively, we could use objc to remove the X button.

          henryaukc 1 Reply Last reply Reply Quote 0
          • henryaukc
            henryaukc last edited by

            @jonB really? We can even remove that 'X' button? That's so powerful... Can we just stop responding to the touch events outside the dialog box? Then no one can stop the script or modify any codes when running the login script.

            1 Reply Last reply Reply Quote 0
            • dgelessus
              dgelessus last edited by

              os.abort() is the "safer" way to force-quit Pythonista, by the way. It should be somewhat cleaner than os._exit(0) or accessing bad memory at least.

              1 Reply Last reply Reply Quote 0
              • henryaukc
                henryaukc last edited by

                Thanks. I am thinking to open a full-screen window so that the user can't press the stop script button or modify the scripts...

                1 Reply Last reply Reply Quote 0
                • henryaukc
                  henryaukc @JonB last edited by

                  @JonB Hi, may I know how to use objc to remove the X button?

                  cvp 1 Reply Last reply Reply Quote 0
                  • ccc
                    ccc last edited by

                    https://omz-software.com/pythonista/docs/ios/ui.html#ui.View.present View.present(hide_close_button=True)

                    cvp 1 Reply Last reply Reply Quote 0
                    • cvp
                      cvp @ccc last edited by

                      @ccc I guess he wants to hide, not the close button, but the start/stop button for a non fullscreen script.

                      1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp @henryaukc last edited by cvp

                        @henryaukc said

                        how to use objc to remove the X button?

                        Please, for the fun, try this script and you will see the start/stop button disappear

                        from objc_util import *
                        import ui
                        
                        w=ObjCClass('UIApplication').sharedApplication().keyWindow()
                        main_view=w.rootViewController().view()
                        
                        def get_toolbar(view, indent):
                        	#get main editor toolbar, by recursively walking the view
                        	sv=view.subviews()
                        	for v in sv:
                        		#print(indent,v._get_objc_classname())
                        		if 'UIImageView' in str(v._get_objc_classname()):  
                        			# <UIImage:0x281108240 named(main: Stop2) {28, 28}>
                        			#print(v.image())
                        			o = v.image()
                        			if o:
                        				with ui.ImageContext(32,32) as ctx:
                        					o.drawAtPoint_(CGPoint(0,0))
                        					ui_image = ctx.get_image()					
                        					#ui_image.show()
                        					#print()
                        				if 'Stop2' in str(o):
                        					#print('+'*40)
                        					OMBarButton = v.superview().superview()
                        					OMBarButton.removeFromSuperview()
                        		tb= get_toolbar(v, indent+'  ')
                        get_toolbar(main_view, '')
                        

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors