-
Notifications
You must be signed in to change notification settings - Fork 5
Custom passcodes
Custom passcodes are often used in tweaks, and are easily available to use in LibPassword.
The first step is to create an ObjC class that implements the LibPassDelegate, this can be done by adding
: NSObject<LibPassDelegate>
to the end of your @interface.
Example:
@interface PassExtender : NSObject<LibPassDelegate>
Then you need to add the method declarations for the LibPassDelegate in your interface, and then implement it in the class.
A sample to add "hello" could be as follows:
@implementation PassExtender
-(BOOL)shouldAllowPasscode:(NSString*)password
{
if ([password isEqualToString:@"hello"])
return YES;
}
@end
Of course, you can compare password
to any string, such as the time, a user-defined passcode, etc. The LibPass code comes with a simple TimeCode tweak which demonstrates using both time and custom passcodes.
It isn't done yet - you haven't registered the function with LibPass. You can do that you can register an instance in your %ctor
. The retain
is used to make sure that the instance of the class, in this case PassExtender
, does not become dealloc'd. You must also import the dlfcn.h header.
Example:
#import <dlfcn.h>
...
%ctor
{
dlopen("/Library/MobileSubstrate/DynamicLibraries/libPass.dylib", RTLD_NOW | RTLD_GLOBAL); // important so that LibPass is loaded, if the tweak starts with a letter before "L" it will load before libPass so we need to make sure that doesn't happen.
[[LibPass sharedInstance] registerDelegate:[[[PassExtender alloc] init] retain]];
}