Added pretty password display prototype to enhance password display

This commit is contained in:
Michael Starke
2017-11-30 16:41:16 +01:00
parent ee418db014
commit 50c38e5672
7 changed files with 100 additions and 1 deletions

View File

@@ -33,6 +33,7 @@
#import "MPReferenceBuilderViewController.h"
#import "NSString+MPPasswordCreation.h"
#import "KPKEntry+MPAdditions.h"
#import "MPDocument.h"
#import "MPIconHelper.h"

View File

@@ -7,6 +7,7 @@
//
#import "MPPickcharsParser.h"
#import "NSString+MPComposedCharacterAdditions.h"
#import <KeePassKit/KeePassKit.h>
@interface MPPickcharsParser ()
@@ -39,7 +40,13 @@
}
- (NSString *)processPickedString:(NSString *)string {
return string;
if(!self.convertToDownArrows) {
return string;
}
for(NSString *character in string.composedCharacters) {
}
}
/*

View File

@@ -26,6 +26,7 @@
@property (nonatomic, readonly) NSUInteger composedCharacterLength;
@property (nonatomic, readonly, copy) NSArray<NSValue *> *composedCharacterRanges; // NSArray of NSValues of NSRanges
@property (nonatomic, readonly, copy) NSArray<NSString *> *composedCharacters; // NSArray of composed characters. For the most part those will be single character strings
- (NSString *)composedCharacterAtIndex:(NSUInteger)index;

View File

@@ -50,4 +50,14 @@
return nil;
}
- (NSArray<NSString *> *)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

View File

@@ -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 <Foundation/Foundation.h>
@interface NSString (MPPrettyPasswordDisplay)
@property (copy) NSAttributedString *passwordPrettified;
@end

View File

@@ -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 <NSValue *> *digitRanges = [self rangesOfCharactersInSet:NSCharacterSet.decimalDigitCharacterSet];
for(NSValue *rangeValue in digitRanges) {
[string addAttribute:NSForegroundColorAttributeName value:NSColor.redColor range:rangeValue.rangeValue];
}
/* symbols */
NSArray <NSValue *> *symbolRanges = [self rangesOfCharactersInSet:NSCharacterSet.symbolCharacterSet];
for(NSValue *rangeValue in symbolRanges) {
[string addAttribute:NSForegroundColorAttributeName value:NSColor.blueColor range:rangeValue.rangeValue];
}
/* punktuation */
NSArray <NSValue *> *punctiationRanges = [self rangesOfCharactersInSet:NSCharacterSet.punctuationCharacterSet];
for(NSValue *rangeValue in punctiationRanges) {
[string addAttribute:NSForegroundColorAttributeName value:NSColor.greenColor range:rangeValue.rangeValue];
}
}
- (NSArray<NSValue *>*)rangesOfCharactersInSet:(NSCharacterSet *)characterSet{
NSRange searchRange = NSMakeRange(0, self.length);
NSMutableArray <NSValue *> *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