PSQLKit Common Login

Picture 1

Alright, after a week of hacking and poking around in areas of the Mac OS that I knew existed, but I hadn't poked around in, the common login panel for the ODBCKit is nearing completion.  This has been an interesting and educational week.  

What you see here, is the new common dialog in the PGSQLKit's PGSQLLogin class.  Using the panel itself is fairly easy.  It requires two pieces.  The first, handle the delegate call from the login panel and then instantiate the PGSQLLogin class and call the beginModalLoginForWindow method passing in your own window.   

In code, the login call itself would look like the following:Picture 2

When the user exits the login panel, the class will call your loginCompleted implementation allowing you to do whatever you may need.  In the following example, it uses the returned connection to retain the connection for use in the lifespan of the application and logs the state using NSLog();.  

Picture 3

In and of itself, this is not terribly complex, but behind the scenes, there is quite a bit of heavy lifting going.  Creating the connections is just a small part of the work here.  In order to make the panel more powerful and flexible, the panel itself embeds logic to save connections in the powerful and cool Keychain.  

If the user enters an account and a name, the dialog will save that connection complete with password in the Keychain for quick retrieval later.  That information can be edited and viewed in the Keychain Access tool, like this:

Picture 4

In addition, it does some things like hiding the location if a saved connection is named by the calling application, and the user and password can also be defaulted by the calling program.  

The intent is that this dialog can be used to ease the need for each application to reinvent the login dialog for connecting to PostgreSQL databases, of course it also provided a chance to learn more about the Keychain.  

That in and of itself made the whole project worthwhile, and the end result is something that should be useful to anyone writing Cocoa apps that use PostreSQL databases.

Copyright Andy 'Dru' Satori, 2006-2007, All Rights Reserved