0

I want to keep password which is given by user in a variable. Where to get password value. I look in code but it is containing only username. I am using MGTwitterengine api in my application. Here is the function which is printing data on console.

-(void)setUsername:(NSString *)newUsername password:(NSString *)newPassword
{
     NSLog(@"uset sername %@ and password %@",newUsername,newPassword);
     ...
}

I debug in all function but I saw this function is running after loggedin. But this is printing null in password value although username is printing well. Actually I I have to trace all tweet value of user. I went through MGTwitterEngine. There is a block of code but it is necessary to write username and password.

Here is the code

MGTwitterEngine *twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self]; 

[twitterEngine setUsername:@"username" password:@"password"]; 
// Get updates from people the authenticated user follows. 

NSString *connectionID = [twitterEngine getFollowedTimelineFor:nil since:nil startingAtPage:0];

Please help me how to keep password ?

DarkDust
  • 90,870
  • 19
  • 190
  • 224
Ajay_Kumar
  • 1,381
  • 10
  • 34
  • 62
  • I don't understand your question, are you asking how can you "save" the password of the user? Also if you are targeting iOS5 for your release consider using TwitterKit – Devraj Jul 01 '11 at 11:22
  • @Devraj Apple's KGB devision shoots developers that mention the top secret "T" word. ;) NDA is still active! – Pripyat Jul 01 '11 at 11:47
  • @DavidSchiefer Oops, I watched the Keynote and there was mention of it, so I thought its knowledge was public but not how it works. Either ways sorry Apple! :) – Devraj Jul 02 '11 at 00:31

1 Answers1

1

Read the developer documentation, it provides all the info you need for something as easy as this. Back to the question, there're a couple of ways how you can save this data.

NSUserDefaults: You can save the username and password using this class like this:

[[NSUserDefaults sharedUserDefaults] setObject:username forKey:@"username"];
[[NSUserDefaults sharedUserDefaults] setObject:username forKey:@"password"];
[[NSUserDefaults sharedUserDefaults] synchronize];

Once you need this data again, call it:

NSString*username = [[NSUserDefaults standardUserDefaults] objectForKey:@"username"];
NSString*password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];

OR:

NSDictionary: If you don't want to rely on NSUserDefaults, you can save the login data in a NSDictionary and save it to your sandbox. This works like this:

NSMutableDictionary*loginDictionary = [[NSMutableDictionary alloc] init];
[loginDictionary setObject:username forKey:@"username"];
[loginDictionary setObject:password forKey:@"password"];
[loginDictionary writeToFile://Your Path Here atomically:NO];

[loginDictionary release];

Then, once you need the data again, read from file:

NSMutableDictionary*loginDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile://Your Path];

NSString*username = [loginDictionary objectForKey:@"username"];
NSString*password = [loginDictionary objectForKey:@"password"];

[loginDictionary release];

Hope it helps!

Pripyat
  • 2,937
  • 2
  • 35
  • 69
  • 1
    I believe that sfhfkeychainutils is more secure than NSUserDefaults, if you need to store passwords – quantumpotato Dec 29 '11 at 22:14
  • Very fair point, but I felt that this user needed an answer that beginners could understand too. I myself would use NSDictionary and encrypt it with AES. – Pripyat Dec 30 '11 at 12:18