Skip to content

Commit

Permalink
Merge pull request #677 from Sequel-Ace/connectionsPrefill
Browse files Browse the repository at this point in the history
Use entered password for favorite if it changed #fixed
  • Loading branch information
Kaspik committed Dec 23, 2020
2 parents 20d4866 + 38037a8 commit 2bf774d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
Expand Up @@ -303,7 +303,7 @@ - (IBAction)initiateConnection:(id)sender
// for increased security.
if (connectionKeychainItemName && !isTestingConnection) {
if ([[keychain getPasswordForName:connectionKeychainItemName account:connectionKeychainItemAccount] isEqualToString:[self password]]) {
[self setPassword:[[NSString string] stringByPaddingToLength:[[self password] length] withString:@"sp" startingAtIndex:0]];
[self setPassword:@"SequelAceSecretPassword"];

[[standardPasswordField undoManager] removeAllActionsWithTarget:standardPasswordField];
[[socketPasswordField undoManager] removeAllActionsWithTarget:socketPasswordField];
Expand All @@ -313,7 +313,7 @@ - (IBAction)initiateConnection:(id)sender

if (connectionSSHKeychainItemName && !isTestingConnection) {
if ([[keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount] isEqualToString:[self sshPassword]]) {
[self setSshPassword:[[NSString string] stringByPaddingToLength:[[self sshPassword] length] withString:@"sp" startingAtIndex:0]];
[self setSshPassword:@"SequelAceSecretPassword"];
[[sshSSHPasswordField undoManager] removeAllActionsWithTarget:sshSSHPasswordField];
}
}
Expand Down Expand Up @@ -2099,9 +2099,8 @@ - (void)initiateMySQLConnectionInBackground
}
}

// Only set the password if there is no Keychain item set or the connection is being tested.
// The connection will otherwise ask the delegate for passwords in the Keychain.
if ((!connectionKeychainItemName || isTestingConnection) && [self password]) {
// Only set the password if there is no Keychain item set or the connection is being tested or the password is different than in Keychain.
if ((isTestingConnection || !connectionKeychainItemName || (connectionKeychainItemName && ![[self password] isEqualToString:@"SequelAceSecretPassword"])) && [self password]) {
[mySQLConnection setPassword:[self password]];
}

Expand Down Expand Up @@ -2291,11 +2290,11 @@ - (void)initiateSSHTunnelConnection

[sshTunnel setParentWindow:[dbDocument parentWindow]];

// Add keychain or plaintext password as appropriate - note the checks in initiateConnection.
if (connectionSSHKeychainItemName && !isTestingConnection) {
// Only set the password if there is no Keychain item set or the connection is being tested or the password is different than in Keychain.
if ((isTestingConnection || !connectionSSHKeychainItemName || (connectionSSHKeychainItemName && ![[self sshPassword] isEqualToString:@"SequelAceSecretPassword"])) && [self sshPassword]) {
[sshTunnel setPassword:[self sshPassword]];
} else if (connectionSSHKeychainItemName) {
[sshTunnel setPasswordKeychainName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
} else if (sshPassword) {
[sshTunnel setPassword:[self sshPassword]];
}

// Set the public key path if appropriate
Expand Down
Expand Up @@ -64,7 +64,7 @@ - (void)awakeFromNib
/**
* Updates the default favorite.
*/
- (IBAction)updateDefaultFavorite:(id)sender
- (IBAction)updateDefaultFavorite:(NSPopUpButton *)sender
{
for (NSMenuItem *item in [defaultFavoritePopup itemArray])
{
Expand Down
22 changes: 11 additions & 11 deletions Source/Controllers/SubviewControllers/SPFieldEditorController.m
Expand Up @@ -260,7 +260,7 @@ - (void)editWithObject:(id)data
if ([bitSheetNULLButton state] == NSOffState && maxBit <= [(NSString*)sheetEditData length])
for (i = 0; i < maxBit; i++)
{
[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", (long)i]]
[(NSButton *)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", (long)i]]
setState:([(NSString*)sheetEditData characterAtIndex:(maxBit - i - 1)] == '1') ? NSOnState : NSOffState];
}

Expand Down Expand Up @@ -1087,11 +1087,11 @@ - (IBAction)bitSheetOperatorButtonWasClicked:(id)sender
switch([sender tag]) {
case 0: // all to 1
for(i=0; i<maxBit; i++)
[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i]] setState:NSOnState];
[(NSButton *)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i]] setState:NSOnState];
break;
case 1: // all to 0
for(i=0; i<maxBit; i++)
[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i]] setState:NSOffState];
[(NSButton *)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i]] setState:NSOffState];
break;
case 2: // negate
for(i=0; i<maxBit; i++)
Expand All @@ -1101,27 +1101,27 @@ - (IBAction)bitSheetOperatorButtonWasClicked:(id)sender
for(i=maxBit-1; i>0; i--) {
[(NSButton*)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i]] setState:[(NSButton*)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i-1]] state]];
}
[[self valueForKeyPath:@"bitSheetBitButton0"] setState:NSOffState];
[(NSButton *)[self valueForKeyPath:@"bitSheetBitButton0"] setState:NSOffState];
break;
case 4: // shift right
for(i=0; i<maxBit-1; i++) {
[(NSButton*)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i]] setState:[(NSButton*)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i+1]] state]];
}
[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", maxBit-1]] setState:NSOffState];
[(NSButton *)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", maxBit-1]] setState:NSOffState];
break;
case 5: // rotate left
aBit = [(NSButton*)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", maxBit-1]] state];
for(i=maxBit-1; i>0; i--) {
[(NSButton*)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i]] setState:[(NSButton*)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i-1]] state]];
}
[[self valueForKeyPath:@"bitSheetBitButton0"] setState:aBit];
[(NSButton *)[self valueForKeyPath:@"bitSheetBitButton0"] setState:aBit];
break;
case 6: // rotate right
aBit = [(NSButton*)[self valueForKeyPath:@"bitSheetBitButton0"] state];
for(i=0; i<maxBit-1; i++) {
[(NSButton*)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i]] setState:[(NSButton*)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i+1]] state]];
}
[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", maxBit-1]] setState:aBit];
[(NSButton *)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", maxBit-1]] setState:aBit];
break;
}
[self updateBitSheet];
Expand Down Expand Up @@ -1187,15 +1187,15 @@ - (void)controlTextDidChange:(NSNotification *)notification
NSUInteger intValue = (NSUInteger)strtoull([[bitSheetIntegerTextField stringValue] UTF8String], NULL, 0);

for(i=0; i<maxBit; i++)
[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i]] setState:NSOffState];
[(NSButton *)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i]] setState:NSOffState];

[bitSheetHexTextField setStringValue:[NSString stringWithFormat:@"%lX", (unsigned long)intValue]];
[bitSheetOctalTextField setStringValue:[NSString stringWithFormat:@"%llo", (long long)intValue]];

i = 0;
while( intValue && i < maxBit )
{
[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i]] setState:( (intValue & 0x1) == 0) ? NSOffState : NSOnState];
[(NSButton *)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%lu", i]] setState:( (intValue & 0x1) == 0) ? NSOffState : NSOnState];
intValue >>= 1;
i++;
}
Expand All @@ -1211,15 +1211,15 @@ - (void)controlTextDidChange:(NSNotification *)notification
[[NSScanner scannerWithString:[bitSheetHexTextField stringValue]] scanHexLongLong: &intValue];

for(i=0; i<maxBit; i++)
[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", (long)i]] setState:NSOffState];
[(NSButton *)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", (long)i]] setState:NSOffState];

[bitSheetHexTextField setStringValue:[NSString stringWithFormat:@"%qX", intValue]];
[bitSheetOctalTextField setStringValue:[NSString stringWithFormat:@"%llo", intValue]];

i = 0;
while( intValue && i < maxBit )
{
[[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", (long)i]] setState:( (intValue & 0x1) == 0) ? NSOffState : NSOnState];
[(NSButton *)[self valueForKeyPath:[NSString stringWithFormat:@"bitSheetBitButton%ld", (long)i]] setState:( (intValue & 0x1) == 0) ? NSOffState : NSOnState];
intValue >>= 1;
i++;
}
Expand Down

0 comments on commit 2bf774d

Please sign in to comment.