mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 12:52:21 +00:00
Using dot syntax for properties
Signed-off-by: michael starke <michael.starke@hicknhack-software.com>
This commit is contained in:
@@ -33,10 +33,10 @@ static NSString *allowedCharactersString(MPPasswordCharacterFlags flags) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NSString *mergeWithoutDuplicates(NSString* baseCharacters, NSString* customCharacters){
|
static NSString *mergeWithoutDuplicates(NSString* baseCharacters, NSString* customCharacters){
|
||||||
NSInteger maxLength =[baseCharacters length] + [customCharacters length];
|
NSInteger maxLength = baseCharacters.length + customCharacters.length;
|
||||||
NSMutableString* mergedCharacters = [NSMutableString stringWithCapacity: maxLength];
|
NSMutableString* mergedCharacters = [NSMutableString stringWithCapacity: maxLength];
|
||||||
[mergedCharacters appendString:baseCharacters];
|
[mergedCharacters appendString:baseCharacters];
|
||||||
[customCharacters enumerateSubstringsInRange: NSMakeRange(0, [customCharacters length])
|
[customCharacters enumerateSubstringsInRange: NSMakeRange(0, customCharacters.length)
|
||||||
options: NSStringEnumerationByComposedCharacterSequences
|
options: NSStringEnumerationByComposedCharacterSequences
|
||||||
usingBlock: ^(NSString *inSubstring, NSRange inSubstringRange, NSRange inEnclosingRange, BOOL *outStop) {
|
usingBlock: ^(NSString *inSubstring, NSRange inSubstringRange, NSRange inEnclosingRange, BOOL *outStop) {
|
||||||
if(![mergedCharacters containsString:inSubstring]){
|
if(![mergedCharacters containsString:inSubstring]){
|
||||||
@@ -50,7 +50,7 @@ static NSString *mergeWithoutDuplicates(NSString* baseCharacters, NSString* cust
|
|||||||
|
|
||||||
+ (NSString *)passwordFromString:(NSString *)source length:(NSUInteger)length {
|
+ (NSString *)passwordFromString:(NSString *)source length:(NSUInteger)length {
|
||||||
NSMutableString *password = [[NSMutableString alloc] initWithCapacity:length];
|
NSMutableString *password = [[NSMutableString alloc] initWithCapacity:length];
|
||||||
while([password length] < length) {
|
while(password.length < length) {
|
||||||
[password appendString:[source randomCharacter]];
|
[password appendString:[source randomCharacter]];
|
||||||
}
|
}
|
||||||
return password;
|
return password;
|
||||||
@@ -63,9 +63,9 @@ static NSString *mergeWithoutDuplicates(NSString* baseCharacters, NSString* cust
|
|||||||
NSString *characters = mergeWithoutDuplicates(
|
NSString *characters = mergeWithoutDuplicates(
|
||||||
allowedCharactersString(allowedCharacters),
|
allowedCharactersString(allowedCharacters),
|
||||||
customCharacters);
|
customCharacters);
|
||||||
while([password length] < length) {
|
while(password.length < length) {
|
||||||
NSString *randomCharacter = [characters randomCharacter];
|
NSString *randomCharacter = [characters randomCharacter];
|
||||||
if([randomCharacter length] > 0) {
|
if(randomCharacter.length > 0) {
|
||||||
[password appendString:randomCharacter];
|
[password appendString:randomCharacter];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -82,7 +82,7 @@ static NSString *mergeWithoutDuplicates(NSString* baseCharacters, NSString* cust
|
|||||||
BOOL useCustomString = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyPasswordUseCustomString];
|
BOOL useCustomString = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyPasswordUseCustomString];
|
||||||
NSString *customString = [[NSUserDefaults standardUserDefaults] stringForKey:kMPSettingsKeyPasswordCustomString];
|
NSString *customString = [[NSUserDefaults standardUserDefaults] stringForKey:kMPSettingsKeyPasswordCustomString];
|
||||||
|
|
||||||
if(useCustomString && [customString length] > 0) {
|
if(useCustomString && customString.length > 0) {
|
||||||
return [customString passwordWithLength:passwordLength];
|
return [customString passwordWithLength:passwordLength];
|
||||||
}
|
}
|
||||||
return [NSString passwordWithCharactersets:characterFlags
|
return [NSString passwordWithCharactersets:characterFlags
|
||||||
@@ -100,17 +100,17 @@ static NSString *mergeWithoutDuplicates(NSString* baseCharacters, NSString* cust
|
|||||||
}
|
}
|
||||||
NSData *data = [NSData dataWithRandomBytes:sizeof(NSUInteger)];
|
NSData *data = [NSData dataWithRandomBytes:sizeof(NSUInteger)];
|
||||||
NSUInteger randomIndex;
|
NSUInteger randomIndex;
|
||||||
[data getBytes:&randomIndex length:[data length]];
|
[data getBytes:&randomIndex length:data.length];
|
||||||
return [self substringWithRange:NSMakeRange(randomIndex % [self length], 1)];
|
return [self substringWithRange:NSMakeRange(randomIndex % self.length, 1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CGFloat)entropyWhithPossibleCharacterSet:(MPPasswordCharacterFlags)allowedCharacters orCustomCharacters:(NSString *)customCharacters {
|
- (CGFloat)entropyWhithPossibleCharacterSet:(MPPasswordCharacterFlags)allowedCharacters orCustomCharacters:(NSString *)customCharacters {
|
||||||
CGFloat alphabetCount = [customCharacters length];
|
CGFloat alphabetCount = customCharacters.length;
|
||||||
if(nil == customCharacters) {
|
if(nil == customCharacters) {
|
||||||
NSString *stringSet = allowedCharactersString(allowedCharacters);
|
NSString *stringSet = allowedCharactersString(allowedCharacters);
|
||||||
alphabetCount = [stringSet length];
|
alphabetCount = stringSet.length;
|
||||||
}
|
}
|
||||||
CGFloat passwordLegnth = [self length];
|
CGFloat passwordLegnth = self.length;
|
||||||
return passwordLegnth * ( log10(alphabetCount) / log10(2) );
|
return passwordLegnth * ( log10(alphabetCount) / log10(2) );
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user