diff --git a/MacPass/MPPasswordCreatorViewController.m b/MacPass/MPPasswordCreatorViewController.m index ecdfad07..5d83dff1 100644 --- a/MacPass/MPPasswordCreatorViewController.m +++ b/MacPass/MPPasswordCreatorViewController.m @@ -148,14 +148,19 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) { #pragma mark Actions - (IBAction)_generatePassword:(id)sender { - if(self.useCustomString) { - if([[self.customCharactersTextField stringValue] length] > 0) { - self.password = [self.customCharactersTextField.stringValue passwordWithLength:self.passwordLength]; + self.password = [NSString passwordWithCharactersets:self.characterFlags + withCustomCharacters:self._customCharacters + length:self.passwordLength]; +} + +- (NSString*)_customCharacters{ + if(self.useCustomString && [[self.customCharactersTextField stringValue] length] > 0) { + return self.customCharactersTextField.stringValue; } - } - else { - self.password = [NSString passwordWithCharactersets:self.characterFlags length:self.passwordLength]; - } + else{ + return @""; + } + } - (IBAction)_toggleCharacters:(id)sender { diff --git a/MacPass/NSString+MPPasswordCreation.h b/MacPass/NSString+MPPasswordCreation.h index 1e40094b..518c21b5 100644 --- a/MacPass/NSString+MPPasswordCreation.h +++ b/MacPass/NSString+MPPasswordCreation.h @@ -26,7 +26,9 @@ typedef NS_OPTIONS(NSUInteger, MPPasswordCharacterFlags) { * * @return new password with only the allowed characters. */ -+ (NSString *)passwordWithCharactersets:(MPPasswordCharacterFlags)allowedCharacters length:(NSUInteger)theLength; ++ (NSString *)passwordWithCharactersets:(MPPasswordCharacterFlags)allowedCharacters + withCustomCharacters:(NSString*)customCharacters + length:(NSUInteger)theLength; /** * Creats a password based on the supplied string * diff --git a/MacPass/NSString+MPPasswordCreation.m b/MacPass/NSString+MPPasswordCreation.m index bb051772..3b9fa1b4 100644 --- a/MacPass/NSString+MPPasswordCreation.m +++ b/MacPass/NSString+MPPasswordCreation.m @@ -42,7 +42,9 @@ static NSString *allowedCharactersString(MPPasswordCharacterFlags flags) { return password; } -+ (NSString *)passwordWithCharactersets:(MPPasswordCharacterFlags)allowedCharacters length:(NSUInteger)length { ++ (NSString *)passwordWithCharactersets:(MPPasswordCharacterFlags)allowedCharacters + withCustomCharacters:(NSString*)customCharacters + length:(NSUInteger)length { NSMutableString *password = [NSMutableString stringWithCapacity:length]; NSString *characters = allowedCharactersString(allowedCharacters); while([password length] < length) { @@ -67,7 +69,9 @@ static NSString *allowedCharactersString(MPPasswordCharacterFlags flags) { if(useCustomString && [customString length] > 0) { return [customString passwordWithLength:passwordLength]; } - return [NSString passwordWithCharactersets:characterFlags length:passwordLength]; + return [NSString passwordWithCharactersets:characterFlags + withCustomCharacters:@"" + length:passwordLength]; } - (NSString *)passwordWithLength:(NSUInteger)length {