Enhanced password input to check and verify

Added repeat password input in settings
New databases without password request on (it's not changed on file until the saved)
This commit is contained in:
michael starke
2013-07-19 01:39:52 +02:00
parent 0e102d3f0f
commit c1b47bdb77
8 changed files with 607 additions and 164 deletions

2
HNHUi

Submodule HNHUi updated: f12405e384...c32f87da30

File diff suppressed because it is too large Load Diff

View File

@@ -18,9 +18,11 @@ typedef NS_ENUM(NSUInteger, MPDatabaseSettingsTab) {
@class MPDocument; @class MPDocument;
@class HNHRoundedSecureTextField; @class HNHRoundedSecureTextField;
@interface MPDatabaseSettingsWindowController : NSWindowController @interface MPDatabaseSettingsWindowController : NSWindowController <NSTextFieldDelegate>
@property (weak) IBOutlet NSTabView *sectionTabView; @property (weak) IBOutlet NSTabView *sectionTabView;
@property (weak) IBOutlet NSButton *saveButton;
@property (weak) IBOutlet NSButton *cancelButton;
/* General Tab */ /* General Tab */
@property (weak) IBOutlet NSTextField *databaseNameTextField; @property (weak) IBOutlet NSTextField *databaseNameTextField;
@@ -28,8 +30,11 @@ typedef NS_ENUM(NSUInteger, MPDatabaseSettingsTab) {
/* Protection */ /* Protection */
@property (weak) IBOutlet HNHRoundedSecureTextField *passwordTextField; @property (weak) IBOutlet HNHRoundedSecureTextField *passwordTextField;
@property (weak) IBOutlet HNHRoundedSecureTextField *passwordRepeatTextField;
@property (weak) IBOutlet NSPathControl *keyfilePathControl; @property (weak) IBOutlet NSPathControl *keyfilePathControl;
@property (weak) IBOutlet NSButton *togglePasswordButton; @property (weak) IBOutlet NSButton *togglePasswordButton;
@property (weak) IBOutlet NSTextField *errorTextField;
- (IBAction)clearKey:(id)sender; - (IBAction)clearKey:(id)sender;
- (IBAction)generateKey:(id)sender; - (IBAction)generateKey:(id)sender;

View File

@@ -14,6 +14,8 @@
#import "HNHRoundedSecureTextField.h" #import "HNHRoundedSecureTextField.h"
#import "NSString+Empty.h"
#import "Kdb.h" #import "Kdb.h"
#import "Kdb4Node.h" #import "Kdb4Node.h"
#import "KdbGroup+MPAdditions.h" #import "KdbGroup+MPAdditions.h"
@@ -24,6 +26,8 @@
@property (nonatomic,assign) BOOL trashEnabled; @property (nonatomic,assign) BOOL trashEnabled;
@property (nonatomic,assign) BOOL showPassword; @property (nonatomic,assign) BOOL showPassword;
@property (nonatomic,assign) BOOL hasValidPasswordOrKey;
@property (nonatomic,weak) NSURL *keyURL;
@end @end
@@ -38,6 +42,7 @@
if(self) { if(self) {
_document = document; _document = document;
_showPassword = NO; _showPassword = NO;
_hasValidPasswordOrKey = NO;
} }
return self; return self;
} }
@@ -47,6 +52,9 @@
NSAssert(_document != nil, @"Document needs to be present"); NSAssert(_document != nil, @"Document needs to be present");
[self.saveButton bind:NSEnabledBinding toObject:self withKeyPath:@"hasValidPasswordOrKey" options:nil];
[self.cancelButton bind:NSEnabledBinding toObject:self withKeyPath:@"hasValidPasswordOrKey" options:nil];
Kdb4Tree *tree = _document.treeV4; Kdb4Tree *tree = _document.treeV4;
if( tree ) { if( tree ) {
[self _setupDatabase:tree]; [self _setupDatabase:tree];
@@ -64,7 +72,7 @@
/* Protection */ /* Protection */
_document.password = [self.passwordTextField stringValue]; _document.password = [self.passwordTextField stringValue];
_document.key = [self.keyfilePathControl URL]; _document.key = [self.keyfilePathControl URL];
/* General */ /* General */
_document.treeV4.databaseDescription = [self.databaseDescriptionTextView string]; _document.treeV4.databaseDescription = [self.databaseDescriptionTextView string];
_document.treeV4.databaseName = [self.databaseNameTextField stringValue]; _document.treeV4.databaseName = [self.databaseNameTextField stringValue];
@@ -72,7 +80,7 @@
/* Display */ /* Display */
/* Advanced */ /* Advanced */
_document.treeV4.recycleBinEnabled = self.trashEnabled; _document.treeV4.recycleBinEnabled = self.trashEnabled;
NSMenuItem *menuItem = [self.selectRecycleBinGroupPopUpButton selectedItem]; NSMenuItem *menuItem = [self.selectRecycleBinGroupPopUpButton selectedItem];
KdbGroup *group = [menuItem representedObject]; KdbGroup *group = [menuItem representedObject];
[_document useGroupAsTrash:group]; [_document useGroupAsTrash:group];
@@ -109,15 +117,68 @@
[self.sectionTabView selectTabViewItemAtIndex:tab]; [self.sectionTabView selectTabViewItemAtIndex:tab];
} }
- (void)setShowPassword:(BOOL)showPassword {
if(_showPassword != showPassword) {
_showPassword = showPassword;
[self.passwordRepeatTextField setStringValue:@""];
[self _verifyPasswordAndKey];
}
}
- (void)setKeyURL:(NSURL *)keyURL {
_keyURL = keyURL;
[self _verifyPasswordAndKey];
}
#pragma mark Actions #pragma mark Actions
- (IBAction)clearKey:(id)sender { - (IBAction)clearKey:(id)sender {
[self.keyfilePathControl setURL:nil]; self.keyURL = nil;
} }
- (IBAction)generateKey:(id)sender { - (IBAction)generateKey:(id)sender {
} }
#pragma makr NSTextFieldDelegate
- (void)controlTextDidChange:(NSNotification *)obj {
[self _verifyPasswordAndKey];
}
#pragma mark Private Helper #pragma mark Private Helper
- (void)_verifyPasswordAndKey {
NSString *password = [self.passwordTextField stringValue];
NSString *repeat = [self.passwordRepeatTextField stringValue];
BOOL hasKey = (self.keyURL != nil);
BOOL keyOk = YES;
if(hasKey) {
keyOk = [self.keyURL checkResourceIsReachableAndReturnError:nil];
}
BOOL hasPassword = ![password isEmpty];
BOOL passwordOk = YES;
if(hasPassword ) {
passwordOk = [password isEqualToString:repeat] || self.showPassword;
}
BOOL hasPasswordOrKey = (hasKey || hasPassword);
keyOk = hasKey ? keyOk : YES;
passwordOk = hasPassword ? passwordOk : YES;
self.hasValidPasswordOrKey = hasPasswordOrKey && passwordOk && keyOk;
if(!hasPasswordOrKey) {
[self.errorTextField setStringValue:NSLocalizedString(@"ERROR_NO_PASSWORD_OR_KEYFILE", "Missing Key or Password")];
return; // alldone
}
if(!passwordOk && !keyOk ) {
[self.errorTextField setStringValue:NSLocalizedString(@"ERROR_PASSWORD_MISSMATCH_INVALID_KEYFILE", "Passwords do not match, keyfile is invalid")];
}
else if(!passwordOk) {
[self.errorTextField setStringValue:NSLocalizedString(@"ERROR_PASSWORD_MISSMATCH", "Passwords do not match")];
}
else {
[self.errorTextField setStringValue:NSLocalizedString(@"ERROR_INVALID_KEYFILE", "Keyfile not valid")];
}
}
- (void)_setupDatabase:(Kdb4Tree *)tree { - (void)_setupDatabase:(Kdb4Tree *)tree {
[self.databaseNameTextField setStringValue:tree.databaseName]; [self.databaseNameTextField setStringValue:tree.databaseName];
[self.databaseDescriptionTextView setString:tree.databaseDescription]; [self.databaseDescriptionTextView setString:tree.databaseDescription];
@@ -140,10 +201,21 @@
- (void)_setupPasswordTab:(Kdb4Tree *)tree { - (void)_setupPasswordTab:(Kdb4Tree *)tree {
[self.passwordTextField setStringValue:_document.password ? _document.password : @""]; [self.passwordTextField setStringValue:_document.password ? _document.password : @""];
[self.keyfilePathControl setURL:_document.key]; [self.passwordRepeatTextField setStringValue:[self.passwordRepeatTextField stringValue]];
self.keyURL = _document.key;
NSDictionary *negateOption = @{ NSValueTransformerNameBindingOption : NSNegateBooleanTransformerName };
[self.passwordTextField bind:@"showPassword" toObject:self withKeyPath:@"showPassword" options:nil]; [self.passwordTextField bind:@"showPassword" toObject:self withKeyPath:@"showPassword" options:nil];
[self.togglePasswordButton bind:NSValueBinding toObject:self withKeyPath:@"showPassword" options:nil]; [self.togglePasswordButton bind:NSValueBinding toObject:self withKeyPath:@"showPassword" options:nil];
[self.passwordRepeatTextField bind:NSEnabledBinding toObject:self withKeyPath:@"showPassword" options:negateOption];
[self.errorTextField bind:NSHiddenBinding toObject:self withKeyPath:@"hasValidPasswordOrKey" options:nil];
[self.keyfilePathControl bind:NSValueBinding toObject:self withKeyPath:@"keyURL" options:nil];
[self.passwordRepeatTextField setDelegate:self];
[self.passwordTextField setDelegate:self];
/* Manually initate the first check */
[self _verifyPasswordAndKey];
} }
- (void)_updateTrashFolders:(Kdb4Tree *)tree { - (void)_updateTrashFolders:(Kdb4Tree *)tree {
@@ -154,7 +226,7 @@
- (NSMenu *)_buildTreeMenu:(Kdb4Tree *)tree { - (NSMenu *)_buildTreeMenu:(Kdb4Tree *)tree {
NSMenu *menu = [[NSMenu alloc] init]; NSMenu *menu = [[NSMenu alloc] init];
[menu setAutoenablesItems:NO]; [menu setAutoenablesItems:NO];
for(Kdb4Group *group in tree.root.groups) { for(Kdb4Group *group in tree.root.groups) {
NSMenuItem *groupItem = [[NSMenuItem alloc] init]; NSMenuItem *groupItem = [[NSMenuItem alloc] init];
[groupItem setImage:group.icon]; [groupItem setImage:group.icon];

View File

@@ -63,9 +63,6 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur
- (void)dealloc { - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
} }
#pragma mark View Handling #pragma mark View Handling
@@ -343,6 +340,7 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur
[_outlineViewController showOutline]; [_outlineViewController showOutline];
} }
#pragma mark NSWindowDelegate #pragma mark NSWindowDelegate
- (void)windowDidUpdate:(NSNotification *)notification { - (void)windowDidUpdate:(NSNotification *)notification {
id firstResonder = [[self window] firstResponder]; id firstResonder = [[self window] firstResponder];
@@ -351,10 +349,16 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur
} }
_firstResponder = firstResonder; _firstResponder = firstResonder;
if([_firstResponder isKindOfClass:[NSView class]]) { if([_firstResponder isKindOfClass:[NSView class]]) {
[self _updateCurrentItem:[NSNotification notificationWithName:@"dummy" object:_firstResponder ]]; //self _updateCurrentItem:[NSNotification notificationWithName:@"dummy" object:_firstResponder ]];
} }
} }
- (void)windowDidBecomeKey:(NSNotification *)notification {
MPDocument *document = [self document];
if(!document.hasPasswordOrKey && document.decrypted) {
[self performSelector:@selector(editPassword:) withObject:nil afterDelay:0.5];
}
}
#pragma mark Helper #pragma mark Helper

View File

@@ -44,11 +44,11 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.3.3</string> <string>0.3.4</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>2511</string> <string>2514</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string> <string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key> <key>NSHumanReadableCopyright</key>

Binary file not shown.

Binary file not shown.