Fix entropy count by merging characters sets before calculating

This commit is contained in:
Patrik Thunström
2016-04-17 23:56:06 +02:00
parent 312fa40eae
commit 62cad6fda0

View File

@@ -105,11 +105,16 @@ static NSString *mergeWithoutDuplicates(NSString* baseCharacters, NSString* cust
}
- (CGFloat)entropyWhithPossibleCharacterSet:(MPPasswordCharacterFlags)allowedCharacters orCustomCharacters:(NSString *)customCharacters {
CGFloat alphabetCount = customCharacters.length;
NSString *characters = nil;
if(nil == customCharacters) {
NSString *stringSet = allowedCharactersString(allowedCharacters);
alphabetCount = stringSet.length;
characters = allowedCharactersString(allowedCharacters);
}
else {
NSString *characters = mergeWithoutDuplicates(
allowedCharactersString(allowedCharacters),
customCharacters);
}
CGFloat alphabetCount = characters.length;
CGFloat passwordLegnth = self.length;
return passwordLegnth * ( log10(alphabetCount) / log10(2) );
}