Day 2: Making a swift macOS password manager for people who hate the cloud
Tags: macos, swift, passwordmanager, cloud
Published: 2019-01-03 00:51:41

---
title: Day 2: Making a swift macOS password manager for people who hate the cloud
published: true
description: Watch as I make a password manager for macOS this month
tags: macos, swift, password manager, cloud
series: Making a swift MacOS password manager for people who hate the cloud
cover_image: https://thepracticaldev.s3.amazonaws.com/i/q6r73zbfbm3mpfs98bu5.jpg
canonical_url: https://streaking.app/posts/day-2-making-a-swift-macos-password-manager-for-people-who-hate-the-cloud-38825a6e9051
---

[<- For Day 1 go here](https://dev.to/swlkr/day-1-making-a-native-macos-password-manager-for-people-who-hate-the-cloud-3j68)

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](https://dev.to/rhymes) comment on the last article

![](https://thepracticaldev.s3.amazonaws.com/i/ofgjul99jqxizl32uury.png)

After a while I realized that CoreData isn't for me. So I decided to bring in some third party libs [stephencelis/SQLite.swift](https://github.com/stephencelis/SQLite.swift) and [evgenyneu/keychain-swift](https://github.com/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:

```swift
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!

```swift
    @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!