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.
[Share Code] Touch ID Authentication in Pythonista
-
I don't think I can submit a pull request, but here's my fork with some improvements:
https://gist.github.com/omz/66a763a9db15dc847690
I've refactored the code a little to make it usable as a module. The
authenticate()
function basically encapsulates all the callback logic, so you can simply call it, and it'll either returnTrue
or raise anAuthFailedException
(there are subclasses for more specific errors).It also supports a timeout, and you can specify whether the device passcode should be allowed as an alternative if TouchID fails.
-
-
I'd do 2 things:
-Implement it in the keychain module( i wanted to do it but i cant find the keychain module)
-add the ability to set a password instead of a passcode -
@hyshai I don't get notifications for Gist comments, so let's move this here... You said that my fork crashes on iPhone 6 / iOS 8.4.1. Could you provide a few more details? Does it crash immediately or after the TouchID dialog is shown. Does @filippocld's version crash as well? Which beta build do you have installed?
-
@omz sorry about that. I figured out what causes the crash - a
policy
with the value of2
causes it. If I changepolicy = 2 if allow_passcode else 1
topolicy = 1
it works fine.(I'm running 160032 on 8.4.1 iPhone 6)
-
I made a module based on your code: https://gist.github.com/d44b83d80f2f77e4f832
To run it you just call
authenticate()
with an optional string if you want to supply a reason. It will returnTrue
if the user authenticated (with either TouchID or passcode) andFalse
if it was cancelled. -
@ProfSpaceCadet nice. Although rather than doing
while result == None: pass
while you're waiting for a result (which will likely burn CPU), would probably be better to add a threading.Event, and wait on that event instead of looping.
-
@gregr , @ProfSpaceCadet , maybe a time out param , maybe default 30 secs
-
@omz said:
I don't think I can submit a pull request, but here's my fork with some improvements:
https://gist.github.com/omz/66a763a9db15dc847690
I've refactored the code a little to make it usable as a module. The
authenticate()
function basically encapsulates all the callback logic, so you can simply call it, and it'll either returnTrue
or raise anAuthFailedException
(there are subclasses for more specific errors).It also supports a timeout, and you can specify whether the device passcode should be allowed as an alternative if TouchID fails.
@omz is the code still up to date? I noticed if it times out my Pythonista_startup script runs. Is it intentional as part of security or has something broken. Testing in Pythonista v2 beta
Edit: for is_available I returned False. If Touch ID is not available, should it not ask for a passcode rather than just returning a message to the console
-
@Phuket2 said:
@omz said:
I don't think I can submit a pull request, but here's my fork with some improvements:
https://gist.github.com/omz/66a763a9db15dc847690
I've refactored the code a little to make it usable as a module. The
authenticate()
function basically encapsulates all the callback logic, so you can simply call it, and it'll either returnTrue
or raise anAuthFailedException
(there are subclasses for more specific errors).It also supports a timeout, and you can specify whether the device passcode should be allowed as an alternative if TouchID fails.
@omz is the code still up to date? I noticed if it times out my Pythonista_startup script runs. Is it intentional as part of security or has something broken. Testing in Pythonista v2 beta
Edit: for is_available I returned False. If Touch ID is not available, should it not ask for a passcode rather than just returning a message to the console
@omz , if you call the authenticate method without Params, cashes straight away. I am guessing it has to do with you reason param default ''. It does not like that. If I change the default in the call, it's fine. Also, timeout works differently if I pass a named param timeout = 20 for example. The exception is raised rather than rerunning my Pythonista_startup (a reboot I guess)
-
@omz Your fork crashes my Pythonista 3 unfortunately, however I've tried HyShai's fix with no change. Here's my implementation.
from func import TouchID cfg['touchIDEnabled'] = True ... if cfg['touchIDEnabled'] == True: fp = TouchID.authenticate('To continue to x, please use fingerprint.', allow_passcode=False)
My TouchID file is the exact same as the original, besides the change HyShai suggested. Probably worth mentioning that my actual script is 1100+ lines long (main reason being I have a very complex UI that I did manually rather than using the builder), which I imagine doesn't help. Any ideas?
Pythonista 3, iOS 10.1.1.
Edit: looks like there's nothing wrong with the module, I tried a similar implementation in another file (obviously massively shorter) and it worked fine. I might have to work on some optimisation, see what happens. I'm on an air2.
Edit2: Simply commenting stuff out, running, uncommenting seems to fix the crashes. Strange but it's happened before to me. ¯\_(ツ)_/¯
-
@omz
Same problem for me, crash in a big script of 250 lines, no problem with a little test script.
Error is "Fatal Python error: Segmentation fault"Crash just after the touchid window, either if correct finger, cancel or timeout!