So part of a new feature that my boss wants added to our app is the ability to track how many incorrect login attempts have been made and if there were 5 attempts within 15 minutes to disable the login feature for 15 minutes. I can do everything except for the comparing of my two NSDate's that are Formatted as "HH:mm:ss". I thought that I could use compare but most of the examples that I've found just show how to see if the two dates are equal to each other or if one is greater than the other, where I just want to find the difference in minutes between the two. Here's what I have for the two dates I want to compare:
I'm using an Array since I have to store the Error Attempts in NSUserDefaults since we need to check within a 15 minute interval so I had to convert the Dates to Strings to store them and then convert them back for the error checking part.
I can do everything except for the comparing of my two NSDate's that are Formatted as "HH:mm:ss". I thought that I could use compare but most of the examples that I've found just show how to see if the two dates are equal to each other or if one is greater than the other, where I just want to find the difference in minutes between the two.
Thanks DenVog and Nobre, that's what I was looking for but couldn't think of the name and tried searching but kept coming up with NSDate Compare results that weren't working.
So part of a new feature that my boss wants added to our app is the ability to track how many incorrect login attempts have been made and if there were 5 attempts within 15 minutes to disable the login feature for 15 minutes. I can do everything except for the comparing of my two NSDate's that are Formatted as "HH:mm:ss". I thought that I could use compare but most of the examples that I've found just show how to see if the two dates are equal to each other or if one is greater than the other, where I just want to find the difference in minutes between the two. Here's what I have for the two dates I want to compare:
I'm using an Array since I have to store the Error Attempts in NSUserDefaults since we need to check within a 15 minute interval so I had to convert the Dates to Strings to store them and then convert them back for the error checking part.
NSDate is a "property object". You can save NSDate objects to plists or NSUserDefaults directly. No need to convert them to strings.
The full list of property list objects: (NSString, NSData, NSDate, NSNumber, NSArray, or NSDictionary objects)
Note that the documentation for NSArray writeToFile:atomically: does not indicate that NSDate is a plist object, but the docs for the NSDictionary version of writeToFile:atomically: do list NSDate as a property list object.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
NSDate is a "property object". You can save NSDate objects to plists or NSUserDefaults directly. No need to convert them to strings.
The full list of property list objects: (NSString, NSData, NSDate, NSNumber, NSArray, or NSDictionary objects)
Note that the documentation for NSArray writeToFile:atomically: does not indicate that NSDate is a plist object, but the docs for the NSDictionary version of writeToFile:atomically: do list NSDate as a property list object.
This may be my limited knowledge but I thought the only way to apply a NSDateFormatter to a Date is to convert it to a string? I really only need to current time, so that's why I was using a Formatter to get just the HH:mm:ss of the login instead of the entire timestamp from just using NSDate. Is there another way of doing so? What I'm doing know is adding the Error Count and Time to a Dictionary and then adding that to the Array so I can have Key values for each (like setObject:CurrentTime forKey:@"ErrorTimeStamp").
You have no need to discard the date part (what happens for instance if the tries span a different day , but within the 15min interval on the hour ?)
Anyway, when you convert it back to NSDate using the formatter, the current date (or a base date) will be added anyway, you can't get rid of the date part, its stored that way. Just store the NSDate object itself
Thanks nobre, I didn't realize that and just had a Log statement output the two dates and sure enough there was all the extra I didn't need. I'll adjust it to just use the Date without formatting. Thanks for the help.
will this work for you? you can put the start time when the user first attempts to login, and for each login there after you can compare the end time to the start time, if its greater than 900 seconds (15 minutes) then you disable login for 15 minutes. which can be using the same method, at that point create a 2nd start time, and not allow another login attempt until the endtime2 is greater than 900.