Enabled display of prettified passwords ind password generator and entry inspector

This commit is contained in:
Michael Starke
2020-07-17 14:23:26 +02:00
parent badd22793d
commit c4d9c10cb8
4 changed files with 25 additions and 15 deletions

View File

@@ -469,6 +469,8 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
/* general */
NSDictionary *nullPlaceholderBindingOptionsDict = @{ NSNullPlaceholderBindingOption: NSLocalizedString(@"NONE", "Placeholder text for input fields if no entry or group is selected")};
NSDictionary *prettyPasswordBindingOptionsDict = @{ NSNullPlaceholderBindingOption: nullPlaceholderBindingOptionsDict[NSNullPlaceholderBindingOption], NSValueTransformerNameBindingOption : MPPrettyPasswordTransformerName };
[self.titleTextField bind:NSValueBinding
toObject:self
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(title))]
@@ -476,7 +478,8 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
[self.passwordTextField bind:NSValueBinding
toObject:self
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(password))]
options:nullPlaceholderBindingOptionsDict];
options:prettyPasswordBindingOptionsDict];
[self.usernameTextField bind:NSValueBinding
toObject:self
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(username))]
@@ -636,7 +639,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
}
- (IBAction)toggleExpire:(NSButton*)sender {
if([sender state] == NSOnState && [self.representedEntry.timeInfo.expirationDate isEqualToDate:[NSDate distantFuture]]) {
if([sender state] == NSOnState && [self.representedEntry.timeInfo.expirationDate isEqualToDate:NSDate.distantFuture]) {
[NSApp sendAction:self.pickExpireDateButton.action to:nil from:self.pickExpireDateButton];
}
}
@@ -651,7 +654,6 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
- (void)_didChangeCurrentItem:(NSNotification *)notificiation {
self.showPassword = NO;
//self.customFieldsTableView.needsDisplay = YES;
}
@end

View File

@@ -27,6 +27,8 @@
#import "MPSettingsHelper.h"
#import "MPDocument.h"
#import "MPModelChangeObserving.h"
#import "MPPrettyPasswordTransformer.h"
#import "MPFlagsHelper.h"
@@ -56,7 +58,6 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
@interface MPPasswordCreatorViewController ()
@property (nonatomic, copy) NSString *password;
@property (copy) NSString *generatedPassword;
@property (strong) IBOutlet NSTextField *passwordTextField;
@property (strong) IBOutlet NSTextField *passwordLengthTextField;
@@ -120,7 +121,7 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
[self.passwordLengthSlider bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(passwordLength)) options:nil];
[self.passwordLengthTextField bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(passwordLength)) options:nil];
[self.passwordTextField bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(password)) options:nil];
[self.passwordTextField bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(password)) options:@{ NSValueTransformerNameBindingOption: MPPrettyPasswordTransformerName }];
[self.entropyIndicator bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(entropy)) options:nil];
[self.entropyTextField bind:NSValueBinding toObject:self withKeyPath:NSStringFromSelector(@selector(entropy)) options:nil];

View File

@@ -41,6 +41,16 @@ NSString *const MPPrettyPasswordTransformerName = @"com.hicknhack.macpass.MPPret
forName:MPPrettyPasswordTransformerName];
}
- (id)reverseTransformedValue:(id)value {
if([value isKindOfClass:NSString.class]) {
return value;
}
if([value isKindOfClass:NSAttributedString.class]) {
return ((NSAttributedString *)value).string;
}
return nil;
}
- (id)transformedValue:(id)value {
if([value isKindOfClass:NSString.class]) {
return ((NSString *)value).passwordPrettified;

View File

@@ -42,9 +42,9 @@
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
blueColor = [NSColor colorWithRed:0.3 green:0.7 blue:1 alpha:1];
orangeColor = [NSColor colorWithRed:0.3 green:0.7 blue:1 alpha:1];
greenColor = [NSColor colorWithRed:0.3 green:0.7 blue:1 alpha:1];
yellowColor = [NSColor colorWithRed:0.3 green:0.7 blue:1 alpha:1];
orangeColor = [NSColor colorWithRed:1 green:0.7 blue:0.3 alpha:1];
greenColor = [NSColor colorWithRed:0.7 green:1 blue:0.3 alpha:1];
yellowColor = [NSColor colorWithRed:1 green:0.7 blue:0.3 alpha:1];
});
/* digits */
@@ -52,14 +52,11 @@
for(NSValue *rangeValue in digitRanges) {
[string addAttribute:NSForegroundColorAttributeName value:blueColor range:rangeValue.rangeValue];
}
/* symbols */
NSArray <NSValue *> *symbolRanges = [self rangesOfCharactersInSet:NSCharacterSet.symbolCharacterSet];
/* symbols and punctuation */
NSMutableCharacterSet *symbolAndPunctuationSet = [NSCharacterSet.symbolCharacterSet mutableCopy];
[symbolAndPunctuationSet formUnionWithCharacterSet:NSCharacterSet.punctuationCharacterSet];
NSArray <NSValue *> *symbolRanges = [self rangesOfCharactersInSet:symbolAndPunctuationSet];
for(NSValue *rangeValue in symbolRanges) {
[string addAttribute:NSForegroundColorAttributeName value:greenColor range:rangeValue.rangeValue];
}
/* punctuation */
NSArray <NSValue *> *punctiationRanges = [self rangesOfCharactersInSet:NSCharacterSet.punctuationCharacterSet];
for(NSValue *rangeValue in punctiationRanges) {
[string addAttribute:NSForegroundColorAttributeName value:orangeColor range:rangeValue.rangeValue];
}
}