Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple passcodes (multiple users) #53

Open
lukeredpath opened this issue Jun 1, 2016 · 0 comments
Open

Support for multiple passcodes (multiple users) #53

lukeredpath opened this issue Jun 1, 2016 · 0 comments

Comments

@lukeredpath
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant