Day 2: Making a swift macOS password manager for people who hate the cloud
Sean Walker
Posted on January 3, 2019
My goal for today is to create a schema! Got ahead of myself yesterday and started to get hung up on how bad xcode and cocoa are. Here’s the schema:
login
- id (int)
- email (text)
- username (text)
- url (text)
- name (text)
- key (uuid)
Alright, so here's me changing my color scheme back to light based on rhymes's comment on the last article
After a while I realized that CoreData isn't for me. So I decided to bring in some third party libs stephencelis/SQLite.swift and evgenyneu/keychain-swift to help me finish before Jan 31st 2020. Here's what I accomplished today in a nutshell:
- Tried to mess with CoreData for 10 minutes!! Decided it was a no go.
- Searched for SQLite integration with Swift directly using the SQLite3 lib, again… not really for me.
- Found SQLite.swift, felt productive after failing with CoreData
- Realized that trying to encrypt text in swift with scrypt is also the wrong thing to do and used the keychain instead with keychain-swift
- Finally productive, created the login table in sqlite and was amazed at how easy it was after using a bunch of other people's code
- Still on my productivity high, switched from Storyboard initializing the view controller to checking the keychain for the master password in appDidFinishLaunching like this:
let storyboard = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: Bundle.main)
let window = storyboard.instantiateController(withIdentifier: "WindowController") as! NSWindowController
let keychain = KeychainSwift()
let masterPassword : String? = keychain.get("MasterPassword")
if masterPassword == nil {
let viewController = storyboard.instantiateController(withIdentifier: "SetMasterPasswordViewController") as! NSViewController
window.contentViewController = viewController
} else {
let viewController = storyboard.instantiateController(withIdentifier: "UnlockViewController") as! NSViewController
window.contentViewController = viewController
}
window.showWindow(self)
Look at all that duplication and those hard coded strings GASP. That's what it takes for me to ship apps in a total of ~24 hours / month folks. I also got the actual setting of the master password working as well, I'm into bonus territory for the day!
@IBAction func setMasterPasswordButtonClicked(_ sender: NSButton) {
if masterPasswordTextField.stringValue.count > 12 {
let kc = KeychainSwift()
kc.set(masterPasswordTextField.stringValue, forKey: "MasterPassword")
}
}
Look at all of those curly braces, it looks like line noise compared to clojure. Alright, I'm looking forward to day 3, I bet with my new found reliance on other people's free code that they wrote (bug free, I'm sure) I can really start cooking with storing data in SQLite and passwords in keychain for different sites/apps!
Posted on January 3, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.