mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-25 14:49:30 +00:00
Added sanity checks to key file selection in unlock screen (fixes #1008)
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
@property (weak) IBOutlet MPPathControl *keyPathControl;
|
||||
@property (weak) IBOutlet NSImageView *messageImageView;
|
||||
@property (weak) IBOutlet NSTextField *messageInfoTextField;
|
||||
@property (strong) IBOutlet NSTextField *keyFileWarningTextField;
|
||||
@property (weak) IBOutlet NSButton *togglePasswordButton;
|
||||
@property (weak) IBOutlet NSButton *enablePasswordCheckBox;
|
||||
@property (weak) IBOutlet NSButton *unlockButton;
|
||||
@@ -50,6 +51,7 @@
|
||||
@property (assign) BOOL showPassword;
|
||||
@property (nonatomic, assign) BOOL enablePassword;
|
||||
@property (copy) passwordInputCompletionBlock completionHandler;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPPasswordInputController
|
||||
@@ -72,6 +74,7 @@
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didSetKeyURL:) name:MPPathControlDidSetURLNotification object:self.keyPathControl];
|
||||
self.messageImageView.image = [NSImage imageNamed:NSImageNameCaution];
|
||||
[self.passwordTextField bind:NSStringFromSelector(@selector(showPassword)) toObject:self withKeyPath:NSStringFromSelector(@selector(showPassword)) options:nil];
|
||||
[self.togglePasswordButton bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(showPassword)) options:nil];
|
||||
@@ -108,7 +111,7 @@
|
||||
self.passwordTextField.placeholderString = NSLocalizedString(@"PASSWORD_INPUT_ENTER_PASSWORD", "Placeholder in the unlock-password input field if password is enabled");
|
||||
}
|
||||
else {
|
||||
self.passwordTextField.placeholderString = NSLocalizedString(@"PASSWORD_INPUT_NO_PASSWORD", "Placeholder in the unlock-password input field if password is disabled");
|
||||
self.passwordTextField.placeholderString = NSLocalizedString(@"PASSWORD_INPUT_NO_PASSWORD", "Placeholder in the unlock-password input field if password is disabled");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,4 +214,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_didSetKeyURL:(NSNotification *)notification {
|
||||
if(notification.object != self.keyPathControl) {
|
||||
return; // wrong sender
|
||||
}
|
||||
NSDocument *document = (NSDocument *)self.windowController.document;
|
||||
NSData *keyFileData = [NSData dataWithContentsOfURL:self.keyPathControl.URL];
|
||||
KPKFileVersion keyFileVersion = [KPKFormat.sharedFormat fileVersionForData:keyFileData];
|
||||
BOOL isKdbDatabaseFile = (keyFileVersion.format != KPKDatabaseFormatUnknown);
|
||||
if(isKdbDatabaseFile) {
|
||||
if([document.fileURL isEqual:self.keyPathControl.URL]) {
|
||||
self.keyFileWarningTextField.stringValue = NSLocalizedString(@"ERROR_CURRENT_DATABASE_FILE_SELECTED_AS_KEY_FILE", "Error message displayed when the current database file is also set as the key file");
|
||||
self.keyFileWarningTextField.hidden = NO;
|
||||
}
|
||||
else {
|
||||
self.keyFileWarningTextField.stringValue = NSLocalizedString(@"ERROR_DATABASE_FILE_SELECTED_AS_KEY_FILE", "Error message displayed when a keepass database file is set as the key file");
|
||||
self.keyFileWarningTextField.hidden = NO;
|
||||
}
|
||||
}
|
||||
else {
|
||||
self.keyFileWarningTextField.stringValue = @"";
|
||||
self.keyFileWarningTextField.hidden = YES;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user