SwiftPasscodeLock icon indicating copy to clipboard operation
SwiftPasscodeLock copied to clipboard

Support for multiple passcodes (multiple users)

Open lukeredpath opened this issue 9 years ago • 0 comments

I'm trying to use SwiftPasscodeLock in a system where multiple users can use an app in a shop environment.

The user needs to identify themselves using a PIN before they can use the system - this PIN maps to an identity token that is used in API requests.

I have a map of PIN code -> token in the keychain, so the PIN code effectively acts like a username.

It doesn't seem possible to use SwiftPasscodeLock in this scenario because it assumes there is only one PIN.

Looking at the code, I can think of various ways of implementing this but for now, it looks like the simplest change that would get me where I want to be is to change the PasscodeRepositoryType protocol so it doesn't return a passcode, but has a query method instead:

protocol PasscodeRepositoryType {
    ...
    func checkPasscode(passcode: [String]) -> Bool
}

The passcode checkin EnterPasscodeState.acceptPasscode() would need to change from:

        guard let currentPasscode = lock.repository.passcode else {
            return
        }

        if passcode == currentPasscode {

To:

        if lock.repository.checkPasscode(passcode) {

I can then implement this function however I want and in my case, check whether the PIN exists in the keychain (amongst many).

The downside is this is not backwards compatible, but a transitional API might be to not remove the var passcode { get } declaration and provide a default implementation of checkPasscode in the protocol:

func checkPasscode(passcode: [String]) -> Bool {
    guard let currentPasscode = passcode else {
            return false
    }

    return currentPasscode == passcode
}

Any thoughts?

lukeredpath avatar Jun 01 '16 18:06 lukeredpath