diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index e0f8fda2..4b7a0db4 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -193,6 +193,7 @@ 4C8F0C6E1FCEE9B900BE157F /* MPPluginConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8F0C6D1FCEE9B900BE157F /* MPPluginConstants.m */; }; 4C8F0C711FCEF91400BE157F /* MPPickcharsParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8F0C701FCEF91400BE157F /* MPPickcharsParser.m */; }; 4C8F0C731FCF1B7A00BE157F /* MPTestPickcharsParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8F0C721FCF1B7A00BE157F /* MPTestPickcharsParser.m */; }; + 4C8F0C791FD05A6A00BE157F /* NSString+MPPrettyPasswordDisplay.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C8F0C781FD05A6A00BE157F /* NSString+MPPrettyPasswordDisplay.m */; }; 4C978E0D19AE54AB003067DF /* MPFlagsHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C978E0C19AE54AB003067DF /* MPFlagsHelper.m */; }; 4CA08DA017A831B200A6544B /* MPAddEntryContextMenuDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA08D9F17A831B200A6544B /* MPAddEntryContextMenuDelegate.m */; }; 4CA0B2ED15BCADAC00654E32 /* SettingsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CA0B2EC15BCADAC00654E32 /* SettingsWindow.xib */; }; @@ -663,6 +664,8 @@ 4C8F0C6F1FCEF91400BE157F /* MPPickcharsParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPPickcharsParser.h; sourceTree = ""; }; 4C8F0C701FCEF91400BE157F /* MPPickcharsParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPPickcharsParser.m; sourceTree = ""; }; 4C8F0C721FCF1B7A00BE157F /* MPTestPickcharsParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MPTestPickcharsParser.m; sourceTree = ""; }; + 4C8F0C771FD05A6A00BE157F /* NSString+MPPrettyPasswordDisplay.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+MPPrettyPasswordDisplay.h"; sourceTree = ""; }; + 4C8F0C781FD05A6A00BE157F /* NSString+MPPrettyPasswordDisplay.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+MPPrettyPasswordDisplay.m"; sourceTree = ""; }; 4C8FB9FA1FC2D0EF003691AA /* MPPlugin_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPPlugin_Private.h; sourceTree = ""; }; 4C93C5701FBDFEF700F36855 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/AutotypeCandidateSelectionView.strings; sourceTree = ""; }; 4C93C5711FBDFEF900F36855 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/AutotypeBuilderView.strings; sourceTree = ""; }; @@ -991,6 +994,8 @@ 4C5807771C64F67000E7171F /* NSString+MPHash.m */, 4CDA35731EBA0CF2003CD59F /* NSString+MPComposedCharacterAdditions.h */, 4CDA35741EBA0CF2003CD59F /* NSString+MPComposedCharacterAdditions.m */, + 4C8F0C771FD05A6A00BE157F /* NSString+MPPrettyPasswordDisplay.h */, + 4C8F0C781FD05A6A00BE157F /* NSString+MPPrettyPasswordDisplay.m */, ); name = Categories; sourceTree = ""; @@ -1846,6 +1851,7 @@ 4C77E37A15B84A240093A587 /* MPAppDelegate.m in Sources */, 4C37A84015B8B474005EF8EE /* MPOutlineDataSource.m in Sources */, 4CA0B2F915BCAF6700654E32 /* MPGeneralSettingsController.m in Sources */, + 4C8F0C791FD05A6A00BE157F /* NSString+MPPrettyPasswordDisplay.m in Sources */, 4C6B7C7D18BE7EB0001D5D77 /* MPDocument+History.m in Sources */, 4CA0B2FC15BCAF8600654E32 /* MPSettingsWindowController.m in Sources */, 4C4F72D118DF704400E8D378 /* DDHotKeyTextField.m in Sources */, diff --git a/MacPass/MPEntryInspectorViewController.m b/MacPass/MPEntryInspectorViewController.m index 58d38424..a18f4c1f 100644 --- a/MacPass/MPEntryInspectorViewController.m +++ b/MacPass/MPEntryInspectorViewController.m @@ -33,6 +33,7 @@ #import "MPReferenceBuilderViewController.h" #import "NSString+MPPasswordCreation.h" +#import "KPKEntry+MPAdditions.h" #import "MPDocument.h" #import "MPIconHelper.h" diff --git a/MacPass/MPPickcharsParser.m b/MacPass/MPPickcharsParser.m index 7b24bfb5..9d8bf5d0 100644 --- a/MacPass/MPPickcharsParser.m +++ b/MacPass/MPPickcharsParser.m @@ -7,6 +7,7 @@ // #import "MPPickcharsParser.h" +#import "NSString+MPComposedCharacterAdditions.h" #import @interface MPPickcharsParser () @@ -39,7 +40,13 @@ } - (NSString *)processPickedString:(NSString *)string { - return string; + if(!self.convertToDownArrows) { + return string; + } + for(NSString *character in string.composedCharacters) { + + } + } /* diff --git a/MacPass/NSString+MPComposedCharacterAdditions.h b/MacPass/NSString+MPComposedCharacterAdditions.h index eb6c92d0..922361ef 100644 --- a/MacPass/NSString+MPComposedCharacterAdditions.h +++ b/MacPass/NSString+MPComposedCharacterAdditions.h @@ -26,6 +26,7 @@ @property (nonatomic, readonly) NSUInteger composedCharacterLength; @property (nonatomic, readonly, copy) NSArray *composedCharacterRanges; // NSArray of NSValues of NSRanges +@property (nonatomic, readonly, copy) NSArray *composedCharacters; // NSArray of composed characters. For the most part those will be single character strings - (NSString *)composedCharacterAtIndex:(NSUInteger)index; diff --git a/MacPass/NSString+MPComposedCharacterAdditions.m b/MacPass/NSString+MPComposedCharacterAdditions.m index 745fe522..fb592376 100644 --- a/MacPass/NSString+MPComposedCharacterAdditions.m +++ b/MacPass/NSString+MPComposedCharacterAdditions.m @@ -50,4 +50,14 @@ return nil; } +- (NSArray *)composedCharacters { + __block NSMutableArray *characters = [[NSMutableArray alloc] init]; + [self enumerateSubstringsInRange:NSMakeRange(0, self.length) + options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) { + [characters addObject:substring]; + }]; + return [characters copy]; +} + + @end diff --git a/MacPass/NSString+MPPrettyPasswordDisplay.h b/MacPass/NSString+MPPrettyPasswordDisplay.h new file mode 100644 index 00000000..8dfd6017 --- /dev/null +++ b/MacPass/NSString+MPPrettyPasswordDisplay.h @@ -0,0 +1,15 @@ +// +// NSString+MPPrettyPasswordDisplay.h +// MacPass +// +// Created by Michael Starke on 30.11.17. +// Copyright © 2017 HicknHack Software GmbH. All rights reserved. +// + +#import + +@interface NSString (MPPrettyPasswordDisplay) + +@property (copy) NSAttributedString *passwordPrettified; + +@end diff --git a/MacPass/NSString+MPPrettyPasswordDisplay.m b/MacPass/NSString+MPPrettyPasswordDisplay.m new file mode 100644 index 00000000..5d10cc4f --- /dev/null +++ b/MacPass/NSString+MPPrettyPasswordDisplay.m @@ -0,0 +1,59 @@ +// +// NSString+MPPrettyPasswordDisplay.m +// MacPass +// +// Created by Michael Starke on 30.11.17. +// Copyright © 2017 HicknHack Software GmbH. All rights reserved. +// + +#import "NSString+MPPrettyPasswordDisplay.h" + +@implementation NSString (MPPrettyPasswordDisplay) + +@dynamic passwordPrettified; + +- (NSAttributedString *)passwordPrettified { + NSMutableAttributedString *attributedPassword = [[NSMutableAttributedString alloc] initWithString:self]; + [self _setAttributesInString:attributedPassword]; + return [attributedPassword copy]; +} + +- (void)_setAttributesInString:(NSMutableAttributedString *)string { + /* digits */ + NSArray *digitRanges = [self rangesOfCharactersInSet:NSCharacterSet.decimalDigitCharacterSet]; + for(NSValue *rangeValue in digitRanges) { + [string addAttribute:NSForegroundColorAttributeName value:NSColor.redColor range:rangeValue.rangeValue]; + } + /* symbols */ + NSArray *symbolRanges = [self rangesOfCharactersInSet:NSCharacterSet.symbolCharacterSet]; + for(NSValue *rangeValue in symbolRanges) { + [string addAttribute:NSForegroundColorAttributeName value:NSColor.blueColor range:rangeValue.rangeValue]; + } + /* punktuation */ + NSArray *punctiationRanges = [self rangesOfCharactersInSet:NSCharacterSet.punctuationCharacterSet]; + for(NSValue *rangeValue in punctiationRanges) { + [string addAttribute:NSForegroundColorAttributeName value:NSColor.greenColor range:rangeValue.rangeValue]; + } +} + +- (NSArray*)rangesOfCharactersInSet:(NSCharacterSet *)characterSet{ + NSRange searchRange = NSMakeRange(0, self.length); + NSMutableArray *ranges = [[NSMutableArray alloc] init]; + while(YES) { + if(searchRange.location == NSNotFound) { + break; + } + NSRange range = [self rangeOfCharacterFromSet:characterSet options:NSCaseInsensitiveSearch range:searchRange]; + if(range.location != NSNotFound) { + [ranges addObject:[NSValue valueWithRange:range]]; + searchRange = NSMakeRange(range.location + range.length, self.length - range.location - range.length); + } + else { + searchRange.location = NSNotFound; + } + } + return [ranges copy]; +} + + +@end