I am trying to make a simple password protected app using a text file to store the password that the user entered. I want to take whats in a text field store it in a file and ultimately compare whats in that file to what the user enters in another text field. here is what I have:
//Setting the string to hold the password the user has entered
NSString *createPassword1 = passwordSet.text;
//creating a muttable array to store the value of createPassword1
NSMutableArray *passwordArray = [NSMutableArray array];
//storing createpassword1 into the first element of the array
[passwordArray addObject:createPassword1];
NSLog(@"%@",[passwordArray objectAtIndex:0]);//seeing if it is stored correctly (it is)
//path for searching for the file
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
//my filename
NSString *fileName = @"PasswordFile.txt";
NSString *fileAndPath = [path stringByAppendingPathComponent:fileName];
if (![[NSFileManager defaultManager] fileExistsAtPath:fileAndPath]) {
[[NSFileManager defaultManager] createFileAtPath:fileAndPath contents:nil attributes:nil];
}
[[[passwordArray objectAtIndex:0] dataUsingEncoding:NSUTF8StringEncoding] writeToFile:fileAndPath atomically:YES];
Any help will be greatly appreciated thank you.