Skip to content

Instantly share code, notes, and snippets.

@alessaba
Last active Oct 27, 2021
Embed
What would you like to do?
TouchID.py
# coding: utf-8
from objc_util import *
ObjCClass('NSBundle').bundleWithPath_('/System/Library/Frameworks/LocalAuthentication.framework').load()
context = ObjCClass('LAContext').alloc().init()
policy = 1 #put 1 if you want to auth with password, 2 with passcode
reason = 'We need you fingerprint to ste...ehm... to log you in'
def funct(_cmd,success,error):
if success:
print 'Autenticated!'
else:
autherr= ObjCInstance(error).localizedDescription()
if str(autherr).startswith('Fallback'):
if console.input_alert('Password') == 'Itsme':
print 'Authenticated!'
else:
print 'WRONG PSW'
if str(autherr).startswith('Application retry'):
print('Wrong Fingerprint!')
if str(autherr).startswith('Biometry'):
print('Too many wrong fingerprints!!')
else:
print autherr
handler=ObjCBlock(funct,restype=None,argtypes=[c_void_p,c_void_p,c_void_p])
context.evaluatePolicy_localizedReason_reply_(policy,reason,handler)
@cclauss
Copy link

cclauss commented Aug 25, 2015

If you wanna improve it make a pull request on the gist

Pull requests are only possible on repos, not on gists.

    print('Authenticated!' if success else ObjCInstance(error))

Fixed spelling on Authenticated.

@alessaba
Copy link
Author

alessaba commented Aug 25, 2015

Yeah, sorry about the pull request, i dont use repos very much :-)

I have improved the script to handle more errors and options and @omz made a fork with exeptions and module style script

@cclauss
Copy link

cclauss commented Aug 25, 2015

This is supercool functionality. A great idea.

A repo would keep us all focused on the latest and greatest version instead of forked gists that Can become out of sync with each other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment