mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 15:12:21 +00:00
Added support for both standard and custom characters sets
This commit is contained in:
@@ -148,14 +148,19 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) {
|
|||||||
#pragma mark Actions
|
#pragma mark Actions
|
||||||
|
|
||||||
- (IBAction)_generatePassword:(id)sender {
|
- (IBAction)_generatePassword:(id)sender {
|
||||||
if(self.useCustomString) {
|
self.password = [NSString passwordWithCharactersets:self.characterFlags
|
||||||
if([[self.customCharactersTextField stringValue] length] > 0) {
|
withCustomCharacters:self._customCharacters
|
||||||
self.password = [self.customCharactersTextField.stringValue passwordWithLength:self.passwordLength];
|
length:self.passwordLength];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString*)_customCharacters{
|
||||||
|
if(self.useCustomString && [[self.customCharactersTextField stringValue] length] > 0) {
|
||||||
|
return self.customCharactersTextField.stringValue;
|
||||||
}
|
}
|
||||||
}
|
else{
|
||||||
else {
|
return @"";
|
||||||
self.password = [NSString passwordWithCharactersets:self.characterFlags length:self.passwordLength];
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)_toggleCharacters:(id)sender {
|
- (IBAction)_toggleCharacters:(id)sender {
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ typedef NS_OPTIONS(NSUInteger, MPPasswordCharacterFlags) {
|
|||||||
*
|
*
|
||||||
* @return new password with only the allowed characters.
|
* @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
|
* Creats a password based on the supplied string
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -42,7 +42,9 @@ static NSString *allowedCharactersString(MPPasswordCharacterFlags flags) {
|
|||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSString *)passwordWithCharactersets:(MPPasswordCharacterFlags)allowedCharacters length:(NSUInteger)length {
|
+ (NSString *)passwordWithCharactersets:(MPPasswordCharacterFlags)allowedCharacters
|
||||||
|
withCustomCharacters:(NSString*)customCharacters
|
||||||
|
length:(NSUInteger)length {
|
||||||
NSMutableString *password = [NSMutableString stringWithCapacity:length];
|
NSMutableString *password = [NSMutableString stringWithCapacity:length];
|
||||||
NSString *characters = allowedCharactersString(allowedCharacters);
|
NSString *characters = allowedCharactersString(allowedCharacters);
|
||||||
while([password length] < length) {
|
while([password length] < length) {
|
||||||
@@ -67,7 +69,9 @@ static NSString *allowedCharactersString(MPPasswordCharacterFlags flags) {
|
|||||||
if(useCustomString && [customString length] > 0) {
|
if(useCustomString && [customString length] > 0) {
|
||||||
return [customString passwordWithLength:passwordLength];
|
return [customString passwordWithLength:passwordLength];
|
||||||
}
|
}
|
||||||
return [NSString passwordWithCharactersets:characterFlags length:passwordLength];
|
return [NSString passwordWithCharactersets:characterFlags
|
||||||
|
withCustomCharacters:@""
|
||||||
|
length:passwordLength];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)passwordWithLength:(NSUInteger)length {
|
- (NSString *)passwordWithLength:(NSUInteger)length {
|
||||||
|
|||||||
Reference in New Issue
Block a user