mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-17 13:39:40 +00:00
@@ -44,6 +44,7 @@
|
|||||||
#import "KPKAttribute.h"
|
#import "KPKAttribute.h"
|
||||||
|
|
||||||
#import "NSError+Messages.h"
|
#import "NSError+Messages.h"
|
||||||
|
#import "NSString+MPPasswordCreation.h"
|
||||||
|
|
||||||
NSString *const MPDocumentDidAddGroupNotification = @"com.hicknhack.macpass.MPDocumentDidAddGroupNotification";
|
NSString *const MPDocumentDidAddGroupNotification = @"com.hicknhack.macpass.MPDocumentDidAddGroupNotification";
|
||||||
NSString *const MPDocumentDidRevertNotifiation = @"com.hicknhack.macpass.MPDocumentDidRevertNotifiation";
|
NSString *const MPDocumentDidRevertNotifiation = @"com.hicknhack.macpass.MPDocumentDidRevertNotifiation";
|
||||||
@@ -443,6 +444,10 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
|||||||
if([self.tree.metaData.defaultUserName length] > 0) {
|
if([self.tree.metaData.defaultUserName length] > 0) {
|
||||||
newEntry.username = self.tree.metaData.defaultUserName;
|
newEntry.username = self.tree.metaData.defaultUserName;
|
||||||
}
|
}
|
||||||
|
NSString *defaultPassword = [NSString passwordWithDefaultSettings];
|
||||||
|
if(defaultPassword) {
|
||||||
|
newEntry.password = defaultPassword;
|
||||||
|
}
|
||||||
[parent addEntry:newEntry];
|
[parent addEntry:newEntry];
|
||||||
[parent.undoManager setActionName:NSLocalizedString(@"ADD_ENTRY", "")];
|
[parent.undoManager setActionName:NSLocalizedString(@"ADD_ENTRY", "")];
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentItemAddedNotification object:self];
|
[[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentItemAddedNotification object:self];
|
||||||
|
|||||||
@@ -436,22 +436,6 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) {
|
|||||||
|
|
||||||
- (void)_didAddItem:(NSNotification *)notification {
|
- (void)_didAddItem:(NSNotification *)notification {
|
||||||
[self.tabView selectTabViewItemAtIndex:MPEntryTabGeneral];
|
[self.tabView selectTabViewItemAtIndex:MPEntryTabGeneral];
|
||||||
|
|
||||||
/* generate and pre-fill password using default password creation settings */
|
|
||||||
NSUInteger passwordLength = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyDefaultPasswordLength];
|
|
||||||
MPPasswordCharacterFlags characterFlags = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyPasswordCharacterFlags];
|
|
||||||
BOOL useCustomString = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyPasswordUseCustomString];
|
|
||||||
NSString *customString = [[NSUserDefaults standardUserDefaults] stringForKey:kMPSettingsKeyPasswordCustomString];
|
|
||||||
|
|
||||||
if(useCustomString) {
|
|
||||||
if([customString length] > 0) {
|
|
||||||
[self.passwordTextField setStringValue:[customString passwordWithLength:passwordLength]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[self.passwordTextField setStringValue:[NSString passwordWithCharactersets:characterFlags length:passwordLength]];
|
|
||||||
}
|
|
||||||
|
|
||||||
[self.titleTextField becomeFirstResponder];
|
[self.titleTextField becomeFirstResponder];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ typedef NS_OPTIONS(NSUInteger, MPPasswordCharacterFlags) {
|
|||||||
* @return Password consisint only of allowed characters
|
* @return Password consisint only of allowed characters
|
||||||
*/
|
*/
|
||||||
+ (NSString *)passwordFromString:(NSString *)source length:(NSUInteger)length;
|
+ (NSString *)passwordFromString:(NSString *)source length:(NSUInteger)length;
|
||||||
|
|
||||||
|
+ (NSString *)passwordWithDefaultSettings;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Creates a random password with only the characters of the receiver
|
* Creates a random password with only the characters of the receiver
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#import "NSString+MPPasswordCreation.h"
|
#import "NSString+MPPasswordCreation.h"
|
||||||
#import "NSData+Random.h"
|
#import "NSData+Random.h"
|
||||||
|
|
||||||
|
#import "MPSettingsHelper.h"
|
||||||
|
|
||||||
NSString *const kMPLowercaseLetterCharacters = @"abcdefghijklmnopqrstuvwxyz";
|
NSString *const kMPLowercaseLetterCharacters = @"abcdefghijklmnopqrstuvwxyz";
|
||||||
NSString *const kMPNumberCharacters = @"1234567890";
|
NSString *const kMPNumberCharacters = @"1234567890";
|
||||||
NSString *const kMPSymbolCharacters = @"!$%&\\|/<>(){}[]=?*'+#-_.:,;";
|
NSString *const kMPSymbolCharacters = @"!$%&\\|/<>(){}[]=?*'+#-_.:,;";
|
||||||
@@ -49,6 +51,19 @@ static NSString *allowedCharactersString(MPPasswordCharacterFlags flags) {
|
|||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (NSString *)passwordWithDefaultSettings {
|
||||||
|
/* generate and pre-fill password using default password creation settings */
|
||||||
|
NSUInteger passwordLength = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyDefaultPasswordLength];
|
||||||
|
MPPasswordCharacterFlags characterFlags = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyPasswordCharacterFlags];
|
||||||
|
BOOL useCustomString = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyPasswordUseCustomString];
|
||||||
|
NSString *customString = [[NSUserDefaults standardUserDefaults] stringForKey:kMPSettingsKeyPasswordCustomString];
|
||||||
|
|
||||||
|
if(useCustomString && [customString length] > 0) {
|
||||||
|
return [customString passwordWithLength:passwordLength];
|
||||||
|
}
|
||||||
|
return [NSString passwordWithCharactersets:characterFlags length:passwordLength];
|
||||||
|
}
|
||||||
|
|
||||||
- (NSString *)passwordWithLength:(NSUInteger)length {
|
- (NSString *)passwordWithLength:(NSUInteger)length {
|
||||||
return [NSString passwordFromString:self length:length];
|
return [NSString passwordFromString:self length:length];
|
||||||
}
|
}
|
||||||
@@ -69,5 +84,4 @@ static NSString *allowedCharactersString(MPPasswordCharacterFlags flags) {
|
|||||||
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