TOMBO source code
Revision | e3b2310ec5f7cfd656fe656871f26f46e87cad38 (tree) |
---|---|
Time | 2012-04-12 22:05:07 |
Author | Hirami <tomohisa.hirami@nift...> |
Commiter | Hirami |
Support password timeout.
@@ -4,6 +4,8 @@ | ||
4 | 4 | |
5 | 5 | @property (strong,nonatomic) NSString *password; |
6 | 6 | |
7 | +- (id)init; | |
8 | + | |
7 | 9 | /* |
8 | 10 | * If current password is not set (including timeout), popup dialog and ask to user. Or not, do nothing. |
9 | 11 | * Note user may be cancel and finally prepare may be failed. |
@@ -11,5 +13,9 @@ | ||
11 | 13 | */ |
12 | 14 | - (BOOL)preparePassword; |
13 | 15 | |
16 | +/* | |
17 | + * Like preparePassword, but this method show password dialog twice. Second input is used to confirm | |
18 | + * the password is correct. | |
19 | + */ | |
14 | 20 | - (BOOL)preparePasswordConfirm; |
15 | 21 | @end |
@@ -1,35 +1,68 @@ | ||
1 | 1 | #import "PasswordManager.h" |
2 | 2 | #import "SinglePasswordDialog.h" |
3 | 3 | |
4 | -@implementation PasswordManager | |
4 | +@implementation PasswordManager { | |
5 | + NSTimer *timer; | |
6 | +} | |
5 | 7 | |
6 | 8 | @synthesize password = _password; |
7 | 9 | |
10 | +- (id)init { | |
11 | + id obj = [super init]; | |
12 | + self.password = nil; | |
13 | + return obj; | |
14 | +} | |
15 | + | |
8 | 16 | - (BOOL)preparePassword { |
9 | - SinglePasswordDialog *dialog = [[SinglePasswordDialog alloc] initWithTitle:@"Password" | |
10 | - message:@"Please input password"]; | |
11 | - NSString *pass = [dialog showAndWait]; | |
12 | - if (pass == nil) return NO; | |
13 | - | |
14 | - self.password = pass; | |
17 | + if (!self.password) { | |
18 | + SinglePasswordDialog *dialog = [[SinglePasswordDialog alloc] initWithTitle:@"Password" | |
19 | + message:@"Please input password"]; | |
20 | + NSString *pass = [dialog showAndWait]; | |
21 | + if (pass == nil) return NO; | |
22 | + | |
23 | + self.password = pass; | |
24 | + } | |
25 | + | |
26 | + [self resetTimer]; | |
15 | 27 | return YES; |
16 | 28 | } |
17 | 29 | |
18 | 30 | - (BOOL)preparePasswordConfirm { |
19 | - SinglePasswordDialog *dialog = [[SinglePasswordDialog alloc] initWithTitle:@"Password" | |
20 | - message:@"Please input password"]; | |
21 | - NSString *pass1 = [dialog showAndWait]; | |
22 | - if (pass1 == nil) return NO; | |
23 | - | |
24 | - dialog = [[SinglePasswordDialog alloc] initWithTitle:@"Confirm" message:@"Input password again"]; | |
25 | - NSString *pass2 = [dialog showAndWait]; | |
26 | - if (pass2 == nil) return NO; | |
27 | - | |
28 | - if (![pass1 isEqualToString:pass2]) { | |
29 | - UIAlertView *mismatch = [[UIAlertView alloc] initWithTitle:@"Warn" message:@"Password mismatch." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; | |
30 | - [mismatch show]; | |
31 | - return NO; | |
31 | + if (!self.password) { | |
32 | + SinglePasswordDialog *dialog = [[SinglePasswordDialog alloc] initWithTitle:@"Password" | |
33 | + message:@"Please input password"]; | |
34 | + NSString *pass1 = [dialog showAndWait]; | |
35 | + if (pass1 == nil) return NO; | |
36 | + | |
37 | + dialog = [[SinglePasswordDialog alloc] initWithTitle:@"Confirm" message:@"Input password again"]; | |
38 | + NSString *pass2 = [dialog showAndWait]; | |
39 | + if (pass2 == nil) return NO; | |
40 | + | |
41 | + if (![pass1 isEqualToString:pass2]) { | |
42 | + UIAlertView *mismatch = [[UIAlertView alloc] initWithTitle:@"Warn" | |
43 | + message:@"Password mismatch." | |
44 | + delegate:nil cancelButtonTitle:@"OK" | |
45 | + otherButtonTitles:nil]; | |
46 | + [mismatch show]; | |
47 | + return NO; | |
48 | + } | |
32 | 49 | } |
50 | + | |
51 | + [self resetTimer]; | |
52 | + | |
33 | 53 | return YES; |
34 | 54 | } |
55 | + | |
56 | +- (void)resetTimer { | |
57 | + if (timer) [timer invalidate]; | |
58 | + timer = [NSTimer scheduledTimerWithTimeInterval:60 | |
59 | + target:self | |
60 | + selector:@selector(fireTimer:) | |
61 | + userInfo:nil | |
62 | + repeats:NO]; | |
63 | +} | |
64 | + | |
65 | +- (void)fireTimer:(NSTimer *)timer { | |
66 | + self.password = nil; | |
67 | +} | |
35 | 68 | @end |