diff options
author | rowanbeentje <rowan@beent.je> | 2009-04-14 01:00:18 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2009-04-14 01:00:18 +0000 |
commit | b485234bc633c6d9a1fb25132ad14dba34a54c97 (patch) | |
tree | 5319af8e4f667c1a43a578e8fd20d7de8afb3014 /Source/TableDocument.m | |
parent | 4b9fd266140ad877b714ea58481e234062f864af (diff) | |
download | sequelpro-b485234bc633c6d9a1fb25132ad14dba34a54c97.tar.gz sequelpro-b485234bc633c6d9a1fb25132ad14dba34a54c97.tar.bz2 sequelpro-b485234bc633c6d9a1fb25132ad14dba34a54c97.zip |
- Add a unique ID to each favourite, which is also used when interacting ith the keychain. This resolves the last part of Issue #186 and associated problems (ie multiple connections via a tunnel with only the port differing - now can store different passwords).
- Duplicate function in prefs now also duplicates the password
- Fix a few places which created a blank keychain entry when no password was present
Diffstat (limited to 'Source/TableDocument.m')
-rw-r--r-- | Source/TableDocument.m | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 49962fcc..1d8ac450 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -428,10 +428,11 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum NSString *user = [self valueForKeyPath:@"selectedFavorite.user"]; NSString *host = [self valueForKeyPath:@"selectedFavorite.host"]; NSString *database = [self valueForKeyPath:@"selectedFavorite.database"]; + int favoriteid = [[self valueForKeyPath:@"selectedFavorite.id"] intValue]; - [keyChainInstance deletePasswordForName:[NSString stringWithFormat:@"Sequel Pro : %@", name] + [keyChainInstance deletePasswordForName:[NSString stringWithFormat:@"Sequel Pro : %@ (%i)", name, favoriteid] account:[NSString stringWithFormat:@"%@@%@/%@", user, host, database]]; - [keyChainInstance deletePasswordForName:[NSString stringWithFormat:@"Sequel Pro SSHTunnel : %@", name] + [keyChainInstance deletePasswordForName:[NSString stringWithFormat:@"Sequel Pro SSHTunnel : %@ (%i)", name, favoriteid] account:[NSString stringWithFormat:@"%@@%@/%@", user, host, database]]; // Remove from favorites array controller @@ -478,7 +479,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum if (![self selectedFavorite]) return nil; - NSString *keychainName = [NSString stringWithFormat:@"Sequel Pro : %@", [self valueForKeyPath:@"selectedFavorite.name"]]; + NSString *keychainName = [NSString stringWithFormat:@"Sequel Pro : %@ (%i)", [self valueForKeyPath:@"selectedFavorite.name"], [[self valueForKeyPath:@"selectedFavorite.id"] intValue]]; NSString *keychainAccount = [NSString stringWithFormat:@"%@@%@/%@", [self valueForKeyPath:@"selectedFavorite.user"], [self valueForKeyPath:@"selectedFavorite.host"], @@ -505,6 +506,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum sshPort:(NSString *)sshPort // no-longer in use { NSString *favoriteName = [NSString stringWithFormat:@"%@@%@", user, host]; + NSNumber *favoriteid = [NSNumber numberWithInt:[[NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]] hash]]; if (![database isEqualToString:@""]) favoriteName = [NSString stringWithFormat:@"%@ %@", database, favoriteName]; @@ -517,13 +519,13 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum [self willChangeValueForKey:@"favorites"]; // write favorites and password - NSMutableDictionary *newFavorite = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:favoriteName, host, socket, user, port, database, nil] - forKeys:[NSArray arrayWithObjects:@"name", @"host", @"socket", @"user", @"port", @"database", nil]]; + NSMutableDictionary *newFavorite = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:favoriteName, host, socket, user, port, database, favoriteid, nil] + forKeys:[NSArray arrayWithObjects:@"name", @"host", @"socket", @"user", @"port", @"database", @"id", nil]]; [favorites addObject:newFavorite]; if (![password isEqualToString:@""]) { [keyChainInstance addPassword:password - forName:[NSString stringWithFormat:@"Sequel Pro : %@", favoriteName] + forName:[NSString stringWithFormat:@"Sequel Pro : %@ (%i)", favoriteName, [favoriteid intValue]] account:[NSString stringWithFormat:@"%@@%@/%@", user, host, database]]; } @@ -1998,13 +2000,15 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum { NSDictionary *favorite = [favorites objectAtIndex:rowIndex]; - [keyChainInstance deletePasswordForName:[NSString stringWithFormat:@"Sequel Pro : %@", favoriteNameBeingChanged] + [keyChainInstance deletePasswordForName:[NSString stringWithFormat:@"Sequel Pro : %@ (%i)", favoriteNameBeingChanged, [[favorite objectForKey:@"id"] intValue]] account:[NSString stringWithFormat:@"%@@%@/%@", [favorite objectForKey:@"user"], [favorite objectForKey:@"host"], [favorite objectForKey:@"database"]]]; - [keyChainInstance addPassword:[passwordField stringValue] - forName:[NSString stringWithFormat:@"Sequel Pro : %@", object] - account:[NSString stringWithFormat:@"%@@%@/%@", [favorite objectForKey:@"user"], [favorite objectForKey:@"host"], [favorite objectForKey:@"database"]]]; - + if ([[passwordField stringValue] length]) { + [keyChainInstance addPassword:[passwordField stringValue] + forName:[NSString stringWithFormat:@"Sequel Pro : %@ (%i)", object, [[favorite objectForKey:@"id"] intValue]] + account:[NSString stringWithFormat:@"%@@%@/%@", [favorite objectForKey:@"user"], [favorite objectForKey:@"host"], [favorite objectForKey:@"database"]]]; + } + favoriteNameBeingChanged = nil; } |