mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-24 16:09:27 +00:00
Added pretty password display prototype to enhance password display
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#import "MPReferenceBuilderViewController.h"
|
||||
|
||||
#import "NSString+MPPasswordCreation.h"
|
||||
#import "KPKEntry+MPAdditions.h"
|
||||
|
||||
#import "MPDocument.h"
|
||||
#import "MPIconHelper.h"
|
||||
|
||||
@@ -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) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
15
MacPass/NSString+MPPrettyPasswordDisplay.h
Normal file
15
MacPass/NSString+MPPrettyPasswordDisplay.h
Normal 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
|
||||
59
MacPass/NSString+MPPrettyPasswordDisplay.m
Normal file
59
MacPass/NSString+MPPrettyPasswordDisplay.m
Normal 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
|
||||
Reference in New Issue
Block a user