Returning "0" each time you retrieve a stored keychain access code from keychain access for an ios application

I use the KeychainItemWrapper class (integrated .h and .m file in the project) to save the passcode in Keychain for the iOS application. Also import the "Security" Framework and "keychianItemWrapper.h" into the project wherever you need it. (# Import, #import "KeychainItemWrapper.h")

I use the code below in the application delegation method to keep the access code in chain access:

if([textfieldPassword1.text isEqual:textfieldPassword2.text]){ NSLog(@"CONGRATS !! PASSCODE MATCHED !!!"); //converting "textfieldPassword1" to NSNumber NSNumber *textfieldPasscode1Num = [NSNumber numberWithInt:[textfieldPassword1.text intValue]]; //saving passcode to the keychain access [keychain setObject:textfieldPasscode1Num forKey:(__bridge id)kSecValueData]; // [keychain setObject:[NSNumber numberWithInt:[textfieldPassword1.text intValue]] forKey:(__bridge id)kSecAttrAccount]; // if passcode matches then load Show Lock Screen Page self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.viewController = [[ViewController alloc] init]; [self.window addSubview:self.viewController.view]; [self.window makeKeyAndVisible]; } 

AND HERE AM RESET PASPODA USING THE BELOW CODE:

 if(_isResetPasscode){ NSLog(@"Code here for Update Passcode in Keychain Access !!!"); _isResetPasscode = FALSE; // "keychain" is object of "KeychainItemWrapper" class [keychain resetKeychainItem]; /* Again setting the new passcode entered by user in keychain access.. IT IS NOT SAVING IN keychain access, where above the same line of code was working for saving passcode in keychain access /* [keychain setObject:resetPasscodeNum forKey:(__bridge id)kSecValueData]; NSLog(@"----Passcode Re-Setted ----!! %@\n",resetPasscodeNum); } 

When I print the keychain access code in the console every time it prints "0". Please help me where I am doing wrong ... Your help will be appreciated!

Thanks at Advance

+6
source share
1 answer

You did not indicate what format the password can be entered. I guess it could be some text. If so, then this line will not be executed if the entered text is actually not a number:

 [textfieldPassword1.text intValue] 

and will return 0;

0
source

Source: https://habr.com/ru/post/923586/


All Articles