From 8d9a6ca881a0cf584646d1345f25f6383586dd1b Mon Sep 17 00:00:00 2001 From: michael starke Date: Tue, 26 Aug 2014 23:18:06 +0200 Subject: [PATCH] Forced password change now is only displayed after unlock and before save. --- MacPass/MPDocumentWindowController.m | 67 ++++++++++++----------- MacPass/MPPasswordEditWindowController.h | 2 +- MacPass/MPPasswordEditWindowController.m | 32 +++++------ MacPass/en.lproj/Localizable.strings | Bin 10528 -> 10544 bytes 4 files changed, 53 insertions(+), 48 deletions(-) diff --git a/MacPass/MPDocumentWindowController.m b/MacPass/MPDocumentWindowController.m index fb4d248e..b78ba1b6 100644 --- a/MacPass/MPDocumentWindowController.m +++ b/MacPass/MPDocumentWindowController.m @@ -215,7 +215,17 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword); [weakDocument saveDocument:sender]; } }; - [self _editPasswordRequiringValidInput:YES]; + [self editPassword:nil]; + return; + } + else if(document.shouldEnforcePasswordChange) { + __weak MPDocument *weakDocument = [self document]; + self.passwordChangedBlock = ^void(BOOL didChangePassword){ + if(didChangePassword) { + [weakDocument saveDocument:nil]; + } + }; + [self _presentPasswordIntervalAlters]; return; } /* All set and good ready to save */ @@ -224,17 +234,18 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword); - (void)saveDocumentAs:(id)sender { self.passwordChangedBlock = nil; MPDocument *document = [self document]; - if(!document.compositeKey) { - __weak MPDocument *weakDocument = [self document]; - self.passwordChangedBlock = ^void(BOOL didChangePassword){ - if(didChangePassword) { - [weakDocument saveDocumentAs:sender]; - } - }; - [self _editPasswordRequiringValidInput:YES]; + if(document.compositeKey) { + [[self document] saveDocumentAs:sender]; return; } - [[self document] saveDocumentAs:sender]; + /* we need to make sure that a password is set */ + __weak MPDocument *weakDocument = [self document]; + self.passwordChangedBlock = ^void(BOOL didChangePassword){ + if(didChangePassword) { + [weakDocument saveDocumentAs:sender]; + } + }; + [self editPassword:nil]; } - (void)exportAsXML:(id)sender { @@ -283,16 +294,10 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword); } - (void)editPassword:(id)sender { - [self _editPasswordRequiringValidInput:YES]; -} - -- (void)_editPasswordRequiringValidInput:(BOOL)canCancel { if(!self.passwordEditWindowController) { self.passwordEditWindowController = [[MPPasswordEditWindowController alloc] initWithDocument:[self document]]; self.passwordEditWindowController.delegate = self; } - /* Disallow empty password if we want to save afterwards, otherwise the dialog keeps poping up */ - self.passwordEditWindowController.allowsEmptyPasswordOrKey = canCancel; [NSApp beginSheet:[self.passwordEditWindowController window] modalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:NULL]; } @@ -454,7 +459,9 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword); [alert setAlertStyle:NSCriticalAlertStyle]; [alert setMessageText:NSLocalizedString(@"ENFORCE_PASSWORD_CHANGE_ALERT_TITLE", "")]; [alert setInformativeText:NSLocalizedString(@"ENFORCE_PASSWORD_CHANGE_ALERT_DESCRIPTION", "")]; - [alert addButtonWithTitle:NSLocalizedString(@"CHANGE_PASSWORD", "")]; + [alert addButtonWithTitle:NSLocalizedString(@"CHANGE_PASSWORD_WITH_DOTS", "")]; + [alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "")]; + [[alert buttons][1] setKeyEquivalent:[NSString stringWithFormat:@"%c", 0x1b]]; [alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(_enforcePasswordChangeAlertDidEnd:returnCode:contextInfo:) contextInfo:NULL]; } else if(document.shouldRecommendPasswordChange) { @@ -462,7 +469,7 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword); [alert setAlertStyle:NSInformationalAlertStyle]; [alert setMessageText:NSLocalizedString(@"RECOMMEND_PASSWORD_CHANGE_ALERT_TITLE", "")]; [alert setInformativeText:NSLocalizedString(@"RECOMMEND_PASSWORD_CHANGE_ALERT_DESCRIPTION", "")]; - [alert addButtonWithTitle:NSLocalizedString(@"CHANGE_PASSWORD", "")]; + [alert addButtonWithTitle:NSLocalizedString(@"CHANGE_PASSWORD_WITH_DOTS", "")]; [alert addButtonWithTitle:NSLocalizedString(@"CANCEL", "")]; [[alert buttons][1] setKeyEquivalent:[NSString stringWithFormat:@"%c", 0x1b]]; [alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(_recommentPasswordChangeAlertDidEnd:returnCode:contextInfo:) contextInfo:NULL]; @@ -491,25 +498,23 @@ typedef void (^MPPasswordChangedBlock)(BOOL didChangePassword); } - (void)_recommentPasswordChangeAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo { - if(returnCode == NSAlertFirstButtonReturn) { - id __weak welf = self; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [welf _editPasswordRequiringValidInput:YES]; - }); - + if(returnCode == NSAlertSecondButtonReturn) { + return; } + id __weak welf = self; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [welf editPassword:nil]; + }); + } - (void)_enforcePasswordChangeAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo { - NSAssert(returnCode == NSAlertFirstButtonReturn, @"Return for password change should always be NSAlertFirstButtonReturn"); + if(NSAlertSecondButtonReturn == returnCode) { + return; + } id __weak welf = self; - self.passwordChangedBlock = ^(BOOL didChangePassword){ - if(!didChangePassword) { - [welf _presentPasswordIntervalAlters]; - } - }; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [welf _editPasswordRequiringValidInput:NO]; + [welf editPassword:nil]; }); } diff --git a/MacPass/MPPasswordEditWindowController.h b/MacPass/MPPasswordEditWindowController.h index bb5fbb99..719448c0 100644 --- a/MacPass/MPPasswordEditWindowController.h +++ b/MacPass/MPPasswordEditWindowController.h @@ -31,8 +31,8 @@ @property (weak) IBOutlet NSTextField *errorTextField; @property (weak) IBOutlet NSButton *changePasswordButton; @property (weak) IBOutlet NSButton *hasPasswordSwitchButton; -@property (nonatomic,assign) BOOL allowsEmptyPasswordOrKey; +//@property (nonatomic,assign) BOOL allowsEmptyPasswordOrKey; @property (weak) id delegate; /** diff --git a/MacPass/MPPasswordEditWindowController.m b/MacPass/MPPasswordEditWindowController.m index 7c4dc1fc..c69c3f6f 100644 --- a/MacPass/MPPasswordEditWindowController.m +++ b/MacPass/MPPasswordEditWindowController.m @@ -35,7 +35,7 @@ - (id)initWithDocument:(MPDocument *)document { self = [super initWithWindow:nil]; if(self){ - _allowsEmptyPasswordOrKey = YES; + //_allowsEmptyPasswordOrKey = YES; _showPassword = NO; _hasValidPasswordOrKey = NO; _currentDocument = document; @@ -55,22 +55,22 @@ return; } self.showPassword = NO; - // TODO: fix initial view for password edit - //[self.passwordTextField setStringValue:_currentDocument.password ? _currentDocument.password : @""]; - //[self.passwordRepeatTextField setStringValue:[self.passwordTextField stringValue]]; - //self.keyURL = _currentDocument.key; NSDictionary *negateOption = @{ NSValueTransformerNameBindingOption : NSNegateBooleanTransformerName }; - [self.hasPasswordSwitchButton bind:NSValueBinding toObject:self withKeyPath:@"enablePassword" options:nil]; - [self.passwordTextField bind:NSStringFromSelector(@selector(showPassword)) toObject:self withKeyPath:NSStringFromSelector(@selector(showPassword)) options:nil]; - [self.passwordTextField bind:NSEnabledBinding toObject:self withKeyPath:@"enablePassword" options:nil]; - [self.togglePasswordButton bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(showPassword)) options:nil]; - [self.togglePasswordButton bind:NSEnabledBinding toObject:self withKeyPath:@"enablePassword" options:nil]; - [self.passwordRepeatTextField bind:NSEnabledBinding toObject:self withKeyPath:NSStringFromSelector(@selector(showPassword)) options:negateOption]; - [self.passwordRepeatTextField bind:NSEnabledBinding toObject:self withKeyPath:@"enablePassword" options:nil]; - [self.errorTextField bind:NSHiddenBinding toObject:self withKeyPath:@"hasValidPasswordOrKey" options:nil]; - [self.changePasswordButton bind:NSEnabledBinding toObject:self withKeyPath:@"hasValidPasswordOrKey" options:nil]; - [self.keyfilePathControl bind:NSValueBinding toObject:self withKeyPath:@"keyURL" options:nil]; + NSString *enablePasswordKeyPath = NSStringFromSelector(@selector(enablePassword)); + NSString *showPasswordKeyPath = NSStringFromSelector(@selector(showPassword)); + NSString *hasValidPasswordOrKeyKeyPath = NSStringFromSelector(@selector(hasValidPasswordOrKey)); + + [self.hasPasswordSwitchButton bind:NSValueBinding toObject:self withKeyPath:enablePasswordKeyPath options:nil]; + [self.passwordTextField bind:showPasswordKeyPath toObject:self withKeyPath:showPasswordKeyPath options:nil]; + [self.passwordTextField bind:NSEnabledBinding toObject:self withKeyPath:enablePasswordKeyPath options:nil]; + [self.togglePasswordButton bind:NSValueBinding toObject:self withKeyPath:showPasswordKeyPath options:nil]; + [self.togglePasswordButton bind:NSEnabledBinding toObject:self withKeyPath:enablePasswordKeyPath options:nil]; + [self.passwordRepeatTextField bind:NSEnabledBinding toObject:self withKeyPath:showPasswordKeyPath options:negateOption]; + [self.passwordRepeatTextField bind:NSEnabledBinding toObject:self withKeyPath:enablePasswordKeyPath options:nil]; + [self.errorTextField bind:NSHiddenBinding toObject:self withKeyPath:hasValidPasswordOrKeyKeyPath options:nil]; + [self.changePasswordButton bind:NSEnabledBinding toObject:self withKeyPath:hasValidPasswordOrKeyKeyPath options:nil]; + [self.keyfilePathControl bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(keyURL)) options:nil]; [self.passwordRepeatTextField setDelegate:self]; [self.passwordTextField setDelegate:self]; @@ -169,7 +169,7 @@ BOOL hasPasswordOrKey = (hasKey || hasPassword); keyOk = hasKey ? keyOk : YES; passwordOk = hasPassword ? passwordOk : YES; - self.hasValidPasswordOrKey = (hasPasswordOrKey || self.allowsEmptyPasswordOrKey ) && passwordOk && keyOk; + self.hasValidPasswordOrKey = hasPasswordOrKey && passwordOk && keyOk; if(!hasPasswordOrKey) { [self.errorTextField setTextColor:[NSColor controlTextColor]]; diff --git a/MacPass/en.lproj/Localizable.strings b/MacPass/en.lproj/Localizable.strings index f4ea55fe9129cca6a240e25de25c633cc7ecd0b6..6ee18d0d7e343669ab4a521896a558000b494586 100644 GIT binary patch delta 24 gcmZ1wv>|B21eM7}{Bo1e2=Gl_p(3^Um`W520D!Rxd;kCd delta 24 gcmdlGv><511eM8lYFv}g2=GnbqawBWl1dy40Dh_oZvX%Q