1

I have a plist with Array title and item0,item1,item2 is dictionary to store title and password of my app.now i want to check for signin process

eneter here now i Want to check for pass and items should be matched when i press submit button to login.i Tried the below code but xcode crashes

-(void)authenticateCredentials 
{ 
NSMutableArray *plistArray = [NSMutableArray arrayWithArray:[self readFromPlist]]; 

for (int i = 0; i< [plistArray count]; i++) 
{ 
 if ([[[plistArray   objectAtIndex:i]objectForKey:@"pass"]isEqualToString:emailTextFeild.text] && [[[plistArray objectAtIndex:i]objectForKey:@"title"]isEqualToString:passwordTextFeild.text]) 
{ 
NSLog(@"Correct credentials"); 
} 

 } 
 }

and

-(NSArray*)readFromPlist
 {
   NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
  NSUserDomainMask, YES); 
  NSString *documentsDirectory = [documentPaths objectAtIndex:0];
 NSString *documentPlistPath = [documentsDirectory stringByAppendingPathComponent:@"XYZ.plist"];

   NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:documentPlistPath];

   NSArray *valueArray = [dict objectForKey:@"title"];

   return valueArray;

 }

the xcode gets crashs ..please check in -(void)authenticateCredentials where i am incorrect?

"Edit" Crash when I select the submit button,Its giving output in nslog correct but crash then , with errorr

 2012-12-07 16:52:54.025 NavTutorial[3029:f803] emailEntry: emailemail@gmail.com
 2012-12-07 16:52:54.057 NavTutorial[3029:f803] passwordEntry: abcd
 2012-12-07 16:52:54.081 NavTutorial[3029:f803] Correct credentials
 2012-12-07 16:52:54.081 NavTutorial[3029:f803] Correct credentials
 2012-12-07 16:52:54.082 NavTutorial[3029:f803] -[__NSCFString objectForKey:]:     unrecognized selector sent to instance 0x68e9c30
 2012-12-07 16:52:54.083 NavTutorial[3029:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x68e9c30'
 *** First throw call stack:
(0x14d7052 0x11c2d0a 0x14d8ced 0x143df00 0x143dce2 0x3e71 0x14d8ec9 0x3735c2 0x37355a 0x418b76 0x41903f 0x417e22 0x39893f 0x398c56 0x37f384 0x372aa9 0x1bcdfa9 0x14ab1c5 0x1410022 0x140e90a 0x140ddb4 0x140dccb 0x1bcc879 0x1bcc93e 0x370a9b 0x252d 0x24a5 0x1)
terminate called throwing an exception
  • While I haven't looked at why your code is crashing, the first thing that I saw is that you are storing user credentials in a plist. This is a **very bad thing** and you should not do it. See SO questions like http://stackoverflow.com/questions/6972092/ios-how-to-store-username-password-within-an-app for recommended methods of storing user credentials. – Peter M Dec 06 '12 at 13:49
  • your code is working correctly. I cross checked it, may be its some thing to do with the textfields. – Pranav Jaiswal Dec 06 '12 at 15:36
  • @Pranav ya I dont know y this problem is coming – SameSung Vs Iphone Dec 06 '12 at 16:47
  • you are certainly doing some other thing wrong as this code works fine at my side ... – spider1983 Dec 07 '12 at 11:15
  • please attach the error log – spider1983 Dec 07 '12 at 11:15
  • there is something else i guess the code is good and working put a break point and then debug i guess you have some other objects also than the dictionary in your plistArray...try deleting the app and then run again. – spider1983 Dec 07 '12 at 11:41
  • I got the problem ,Its in the loop ,firstly time its shows correct credentials ..then again goes to the loop ..again prints correct credentials...then 3rd time the error comes which is above...and If write Return; to complete its moves outside the loop..that is been solved now :) – SameSung Vs Iphone Dec 07 '12 at 12:12
  • Very bad to store credentials in plist. plist files are visible to everyone once your app is compiled. You should be store credentials and such using Keychain which is encrypted. – Popeye Dec 07 '12 at 12:19
  • @spider1983 did u check problem in chat room – SameSung Vs Iphone Dec 08 '12 at 05:59

2 Answers2

1

Agreed with Peter M, you shouldn't store them locally, at least in plain text. It would help a lot if you could post the error stack, so we could see what's failing.

supermarin
  • 638
  • 6
  • 11
1

I was my fault actually .. the code is in code so executes again and again ..then crashes...but when i put Return to exit from the for loop ...its works fine...small but powerful mistake.