Q:

Is it possible to delete a password for an account item in the iOS keychain without deleting the entire item?

I have been learning about using the Keychain to store username and password combinations.  I have the following method called "clear Password" but it seems to delete the entire keychain item for the account name:
-(OSStatus)clearPassword{

 NSDictionary *query =  @{ (__bridge  id)kSecClass :  (__bridge  id)kSecClassGenericPassword,
                          (__bridge  id)kSecAttrAccount : self.accountName};

CFDictionaryRef queryRef = (__bridge CFDictionaryRef)query;
OSStatus status =  SecItemDelete(queryRef);
NSAssert(status == errSecSuccess || errSecItemNotFound, @"Unable to delete keychain item");

return status;

}

is it possible to delete JUST the password for a specific account Name so that I would keep the account name in the keychain with no password so that when the user goes to log in the app I can check if the accountname they entered is in the keychain already?  If so how would I formulate the query Dictionary to accomplish this?

A:

I agree with Krumelur's comment. When I've done this in the past, I've stored the last signed on username in the NSUserDefaults. If that username has an entry in the keychain, the user is signed in automatically. If not, the user is prompted to sign in and their credentials are stored in the keychain until they sign back out.

