Skip to content
This repository has been archived by the owner on May 13, 2019. It is now read-only.

Passcode asked again even if the app is deleted and reinstalled #10

Open
ggould75 opened this issue Jul 20, 2012 · 5 comments
Open

Passcode asked again even if the app is deleted and reinstalled #10

ggould75 opened this issue Jul 20, 2012 · 5 comments

Comments

@ggould75
Copy link

I noticed that if you have the passcode ON and you delete the app and then reinstall it again, at the first launch the passcode is requested again.
This is because the passcode is still saved inside of the keychain.
I solved in this way: because my app had already a flag that said when it was launched for the first time, I used this flag also to check the existence of the passcode in the keychain. If it exists I delete it.

@kalaichelvan
Copy link

How did you achieve that? Can you share the code?

@aporat
Copy link
Owner

aporat commented Mar 4, 2013

@ggould75 if you post the code changes, or open a pull request, i'll add it to the demo app. sounds like an important feature to have

@kalaichelvan
Copy link

i managed to do so anyway

below is my code

  • (void)handleFirstTime
    {
    BOOL firstTime = [[NSUserDefaults standardUserDefaults] boolForKey:@"FirstTime"];
    if (firstTime) {

                      if ([KKKeychain setString:@"NO" forKey:@"passcode_on"]) {
                          [KKKeychain setString:@"" forKey:@"passcode"];
                      }
    

    }
    }

  • (id)init
    {
    if ((self = [super init])) {
    [self handleFirstTime];
    }
    return self;
    }

@ggould75
Copy link
Author

I was doing something very similar:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    ....
    [[KKPasscodeLock sharedLock] setDefaultSettings];    

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"ApplicationRanBefore"] == NO)
        [self _clearKeychainData];

    ....
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"ApplicationRanBefore"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

/**
 * Call this method only if it is the first time the application is started!
 * It will delete all the keychain data about the passcode if they are still existing.
 * This avoid the passcode to be asked again if you have the passcode on, delete the app and reinstall it again
 */
- (void)_clearKeychainData {
    BOOL passcodeOn = [[KKKeychain getStringForKey:@"passcode_on"] isEqualToString:@"YES"];

    if (passcodeOn) {
        BOOL res1 = [KKKeychain deleteStringForKey:@"passcode_on"];
        BOOL res2 = [KKKeychain deleteStringForKey:@"passcode"];
        BOOL res3 = [KKKeychain deleteStringForKey:@"erase_data_on"];
        if (res1 == NO || res2 == NO || res3 == NO)
            NSLog(@"Error deleting keychain data!");
    }
}

@valeriomazzeo
Copy link
Contributor

you can do it using my fork calling resetSettings

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants