DEV Community

Cover image for Day 3: Making a swift macOS password manager for people who hate the cloud
Sean Walker
Sean Walker

Posted on • Originally published at streaking.app

Day 3: Making a swift macOS password manager for people who hate the cloud

<- For Day 2 go here

My goal for today is to use the master password to unlock the app and show a blank screen where the list of passwords will be! Let's do it!

After quite a bit of searching around for various things like how to declare classes and then how to declare structs and then how to fill in a tableView and also how to switch the view controller in the window:

I made some tangible progress!

Here's the code for checking the master password and showing a different view controller, the key for me was self.view.window?.contentViewController = viewController

    @IBAction func unlockButtonPressed(_ sender: NSButton) {
        let keychain = KeychainSwift()
        let masterPassword : String? = keychain.get("MasterPassword")

        if masterPassword == masterPasswordTextField.stringValue {
            let storyboard = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: Bundle.main)
            let viewController = storyboard.instantiateController(withIdentifier: "PasswordListViewController") as! NSViewController
            self.view.window?.contentViewController = viewController
        }
    }

I also messed around with the password list view, but I think that's something I'll have to get to tomorrow, I am still working a full time job after all

import Cocoa
import KeychainSwift

struct Login {
    let id: Int64
    let username: String?
    let email: String?
    let key: String
}

class PasswordListViewController: NSViewController {
    let logins = [Login]()

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override var representedObject: Any? {
        didSet {

        }
    }

    func numberOfRows(in tableView: NSTableView) -> Int {
        return logins.count
    }

    func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
        return logins[row]
    }
}

Tune in tomorrow for Day 4 and actually adding passwords and showing them in that table view! There's going to be some rough and tumble SQLite action.

Top comments (2)

Collapse
 
jacobherrington profile image
Jacob Herrington (he/him)

Awesome project idea -- will this be open source when you finish the series?

Collapse
 
swlkr profile image
Sean Walker

Hey thanks! You bet your sweet cheeks it'll be open source when I finish the series!