GithubHelp home page GithubHelp logo

velikanov / swiftpasscodelock Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yankodimitrov/swiftpasscodelock

200.0 9.0 51.0 5.09 MB

An iOS passcode lock with TouchID authentication written in Swift.

License: MIT License

Swift 97.94% Objective-C 1.02% Ruby 1.04%

swiftpasscodelock's Introduction

PasscodeLock

A Swift implementation of passcode lock for iOS with TouchID authentication.

Originally created by @yankodimitrov, hope you're doing well.

Installation

PasscodeLock requires Swift 2.0 and Xcode 7

Podfile

To integrate PasscodeLock into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

pod 'PasscodeLock', '~> 1.0.2'

Then, run the following command:

$ pod install

Add the following line to your Cartfile

github "velikanov/SwiftPasscodeLock"

Usage

  • Create an implementation of the PasscodeRepositoryType protocol.
import UIKit
import PasscodeLock

class PasscodeRepository: PasscodeRepositoryType {
    
    var hasPasscode: Bool = true
    var passcode: [String]?
    
    func savePasscode(passcode: [String]) {}
    
    func deletePasscode() {}
    
}
  • Create an implementation of the PasscodeLockConfigurationType protocol and set your preferred passcode lock configuration options. If you set the maximumInccorectPasscodeAttempts to a number greather than zero, when user will reach that number of incorrect passcode attempts a notification with name PasscodeLockIncorrectPasscodeNotification will be posted on the default NSNotificationCenter.
import UIKit
import PasscodeLock

class PasscodeLockConfiguration: PasscodeLockConfigurationType {
    let repository: PasscodeRepositoryType
    var passcodeLength = 4 // Specify the required amount of passcode digits
    var isTouchIDAllowed = true // Enable Touch ID
    var shouldRequestTouchIDImmediately = true // Use Touch ID authentication immediately
    var maximumInccorectPasscodeAttempts = 3 // Maximum incorrect passcode attempts
    
    init(repository: PasscodeRepositoryType) {
        self.repository = repository
    }
    
    init() {
        self.repository = PasscodeRepository() // The repository that was created earlier
    }
}
  • Create an instance of the PasscodeLockPresenter class. Next inside your UIApplicationDelegate implementation call it to present the passcode in didFinishLaunchingWithOptions and applicationDidEnterBackground methods. The passcode lock will be presented only if your user has set a passcode.

  • Allow your users to set a passcode by presenting the PasscodeLockViewController in .SetPasscode state:

let configuration = ... // your implementation of the PasscodeLockConfigurationType protocol

let passcodeViewController = PasscodeLockViewController(state: .SetPasscode, configuration: configuration)

presentViewController(passcodeViewController, animated: true, completion: nil)

You can present the PasscodeLockViewController in one of the four initial states using the LockState enumeration options: .EnterPasscode, .SetPasscode, .ChangePasscode, .RemovePasscode.

Also you can set the initial passcode lock state to your own implementation of the PasscodeLockStateType protocol.

Customization

Custom Design

The PasscodeLock will look for PasscodeLockView.xib inside your app bundle and if it can't find it will load its default one, so if you want to have a custom design create a new xib with the name PasscodeLockView and set its owner to an instance of PasscodeLockViewController class.

Keep in mind that when using custom classes that are defined in another module, you'll need to set the Module field to that module's name in the Identity Inspector:

Then connect the view outlet to the view of your xib file and make sure to conenct the remaining IBOutlets and IBActions.

PasscodeLock comes with two view components: PasscodeSignPlaceholderView and PasscodeSignButton that you can use to create your own custom designs. Both classes are @IBDesignable and @IBInspectable, so you can see their appearance and change their properties right inside the interface builder:

Localization

Take a look at PasscodeLock/en.lproj/PasscodeLock.strings for the localization keys. Here again the PasscodeLock will look for the PasscodeLock.strings file inside your app bundle and if it can't find it will use the default localization file.

Demo App

The demo app comes with a simple implementation of the PasscodeRepositoryType protocol that is using the NSUserDefaults to store and retrieve the passcode. In your real applications you will probably want to use the Keychain API. Keep in mind that the Keychain records will not be removed when your user deletes your app.

swiftpasscodelock's People

Contributors

chi-patrickhampton avatar happylance avatar jmnavarro avatar jrmsklar avatar le4ker avatar maximbilan avatar readmecritic avatar velikanov avatar yankodimitrov avatar ziogaschr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftpasscodelock's Issues

cancelable TouchId prompt when restoring the app from background

Hi guys,

I have touchID prompt enabled, and when i put the app in background, and bring it back few seconds later, even though PasscodeLock is not yet triggered, i get this touchID prompt by iOS which you can press cancel to bypass! is there a way to stop it from happening?

Cannot install via carthage / Xcode 8.3.1 into Swift 3 Project

I added github "velikanov/SwiftPasscodeLock" to my cartfile
then I ran: carthage update SwiftPasscodeLock --platform iOS

I get:

The following build commands failed:
	Check dependencies
(1 failure)
** BUILD FAILED **c

In log file it says:

/usr/bin/xcrun xcodebuild -project /Users/th/Developer/AppStack/Projects/Vaccy_iOS/Repo/Vaccy/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock.xcodeproj -scheme PasscodeLock -configuration Release -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean buildBuild settings from command line:
    BITCODE_GENERATION_MODE = bitcode
    CARTHAGE = YES
    CODE_SIGN_IDENTITY = 
    CODE_SIGNING_REQUIRED = NO
    ONLY_ACTIVE_ARCH = NO
    SDKROOT = iphoneos10.3

=== CLEAN TARGET PasscodeLock OF PROJECT PasscodeLock WITH CONFIGURATION Release ===

Check dependencies
“Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.
“Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

=== BUILD TARGET PasscodeLock OF PROJECT PasscodeLock WITH CONFIGURATION Release ===

Check dependencies
“Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.
“Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

I think you must specify the SWIFT_VERSION in your Projects Targets to Swift 3 in Build Settings Tab.
Could you do that?

Landscape view?

How will we deal with the landscape view?
Now it looks just not-so-good…

Correct typos

https://github.com/velikanov/SwiftPasscodeLock/blob/master/PasscodeLock/Protocols/PasscodeLockStateType.swift#L18

https://github.com/velikanov/SwiftPasscodeLock/blob/master/PasscodeLock/Protocols/PasscodeLockConfigurationType.swift#L17

maximumInccorectPasscodeAttempts should be maximumIncorrectPasscodeAttempts

https://github.com/velikanov/SwiftPasscodeLock/blob/master/PasscodeLock/PasscodeLockViewController.swift#L228

animatePlacehodlerAtIndex should be animatePlaceholderAtIndex


unfortunately, fixing this will break backward compatibility in the case when users have created their own States or Configurations (they probably will)

dismissPasscodeLock(animated: Bool = true) called many times?

Thanks for the great effort maintaining this library!

Please refer to the screenshot below captured after repeatedly putting the Demo app into background, then to foreground to unlock, and background again:
screen shot 2017-05-26 at 6 33 37 pm

It appears that the method dismissPasscodeLock(animated: Bool = true) will be called many times, is that the expected behaviour? I was testing why the dismiss animation only works for the first time unlock but not the subsequent unlock, then found this.

Please advise.

Custom Design

Migrated Issue (yankodimitrov#25)

@kiokumicu commented on Oct 19

Hi!
I compile framework with Carthage, and add PasscodeLockView.xib, PasscodeSignButton.swift, PasscodeSignPlaceholderView.swift to project.
For PasscodeLockView.xib set owner PasscodeLockViewController class.
After compile passcode show normal, but after tap on number pad got error "PasscodeLock was compiled with optimization - stepping may behave oddly; variables may not be available."
What am i doing wrong ?

@guidelfrate commented on Oct 27

Same problem here! :/
Seems to be something related to the placeholders. I checked all connections and everything is fine.

@gblotter commented on Oct 27

I've been seeing similar weirdnesses and there actually is an open radar: https://openradar.appspot.com/23114017

@guidelfrate commented on Oct 27

@gblotter, really there is a problem with @IBInspectable and @IBDesignable. But I think I solved this copying PasscodeSignButton.swift and PasscodeSignPlaceholderView.swift to my project.

Now my XIB have correct buttons and placeholder, and I can change its properties in Interface Builder, but exactly how @kiokumicu said, I got the error when I tap on any number.

No errors are throw when I use the same XIB on Demo Project. What are we missing?

@guidelfrate commented on Oct 28

I found a temporary solution: using Carthage, I replaced the PasscodeLockView.xib found in /Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock by my custom XIB. Then I compiled the framework again using carthage build. Remember to remove your custom XIB from your project, since it is embedded directly in the framework now.

As alternative, you can add a Run Script build phase that invokes Carthage like so:
/usr/local/bin/carthage build --platform "$PLATFORM_NAME" "$SRCROOT".

For now it works, but it should work as described out of box. I'm looking forward for a definitive solution. :)

@velikanov commented an hour ago

have anybody a working example of extending the PasscodeLockView.xib?
I just don't understand what I need to do to make this happen

Swift 4.2 Support

This library doesn't build with the latest Xcode/Swift.

Are there plans to update this? Is this project still maintained?

License

Please add clear LICENSE information to this project, including copyright strings.

Touch ID misbehaviour

The case is:

  1. Set the passcode
  2. Inactive the app
  3. Back to the app
  4. Unlock with Touch ID
  5. Remove the passcode
  6. Inactive the app
  7. Back to the App

The expectation is normal use the app, however, a touch ID panel is there. Although I can press cancel and use the app normally, it should be a bug.

When looking into the Library, there should be a coding error in PasscodeLockViewController.swift
in func authenticateWithBiometrics, it should also check the passcodeConfiguration.repository.hasPasscode.
Please update the library, Thanks.

Can't set TouchId reason at runtime

Hi

I have an app that requires the user to authenticate against a server with user credentials before accessing the app. I am using a combination of Pin and/or TouchId depending on device capabilities so that the user doesn't have to manually enter their credentials each time.

When using this control with TouchId, I'd like to have a way of injecting the TouchId reason at run time. I can't use the static .strings file because I need to include data in the reason that I'll only know at run time.

mainWindow's windowLevel should not be changed

Changing the main window's windowLevel will cause some unexpected issues, such as using the library with Intercom: https://github.com/intercom/intercom-ios because the Intercom window is using windowLevel = 0.1 or some other values.

This library should use a value less than 0 to be the windowLevel for it's private passcodeLockWindow, and never change the windowLevel of the main window.

When presenting the passcodeLockWindow, it's window level can be a bigger number (such UIWindowLevelStatusBar - 1), but once it's dismissed, it should be set back to a number less than UIWindowLevelNormal.

deletePasscode() Not Getting Called.

Hey guys.

First, thanks for forking and reviving this project. While the documentation could use some improvement, I really like this component and it's a shame the original maintainer has basically abandoned the project.

But anyway, to the point:

Like the title says, deletePasscode() doesn't seem to be getting called at all. Here's some code:

It presents the view controller without any issues:

        let configuration = PasscodeLockConfiguration() 
                let passcodeViewController = PasscodeLockViewController(state: .RemovePasscode, configuration: configuration)
                presentViewController(passcodeViewController, animated: true, completion: nil)

The PasscodeLockConfiguration and PasscodeLockRepository look like this:

let MignoriUserAccount = "com.ios.fairese.Mignori.LocksmithUserAccount.Default"

struct PasscodeLockConfiguration: PasscodeLockConfigurationType {

    let repository: PasscodeRepositoryType
    let passcodeLength = 4
    var isTouchIDAllowed = Settings.lockScreenPasscodeSettingsSupportTouchID
    let shouldRequestTouchIDImmediately = true
    let maximumInccorectPasscodeAttempts = -1

    init(repository: PasscodeRepositoryType) {

        self.repository = repository
    }

    init() {
        self.repository = LocksmithPasscodeRepository()
    }
}

class LocksmithPasscodeRepository: PasscodeRepositoryType {

    var passcode: [String]? {
        return Locksmith.loadDataForUserAccount(MignoriUserAccount)?["passcode"] as? [String]
    }

    var hasPasscode: Bool {
        get {
            return Locksmith.loadDataForUserAccount(MignoriUserAccount) != nil
        }
    }

    func savePasscode(passcode: [String]) {
        do {
            Collector.logEvent("Passcode", withParameters: ["State" : "Enabled"])
            try Locksmith.deleteDataForUserAccount(MignoriUserAccount) // There is no "update password" method sooo yeah.
            try Locksmith.saveData(["passcode": passcode], forUserAccount: MignoriUserAccount)
        } catch let e {
            Collector.logEvent("Failed to Save Passcode", withParameters: ["message" : "\(e)"])
        }
    }

    func deletePasscode() {
        print("bro?")
        do {
            try Locksmith.deleteDataForUserAccount(MignoriUserAccount)
            Collector.logEvent("Passcode", withParameters: ["State" : "Disabled"])
        } catch let e {
            print("Wut err \(e)")
            Collector.logEvent("Failed to Remove Passcode", withParameters: ["message" : "\(e)"])
        }
    }
}

The print("bro?") line never gets executed, so let alone the rest of the lines inside the deletePasscode method. The other three methods get called with no issue, but for some reason deletePasscode doesn't get called, not even when the view controller is presented and I put in my passcode to remove it.

Keychain support (originally: Suggestion)

Migrated issue (yankodimitrov#28)

@karlml commented on Nov 17

It would be great to see this implemented with keychain

@waltermvp commented 25 days ago

@yankodimitrov I have a implementation already done. Should I send a PR?

@twofish187 commented 21 days ago

Can you please implement the secure splash view in this new version?

@waltermvp commented 20 days ago

What secure splash screen?

@twofish187 commented 20 days ago

When the taskmanager in iOS is called and the content of the app is blurred out. In a previous version this was implemented by adding a "splashview". So was it called in code.

@waltermvp commented 20 days ago

@twofish187 please create a new issue this is a unrelated topic

PasscodeLockPresenter not showing passcode screen

I'm calling:

let presenter = PasscodeLockPresenter(mainWindow: UIApplication.shared.keyWindow, configuration: configuration)
presenter.presentPasscodeLock()

from didFinishLaunchingWithOptions and applicationDidEnterBackground but it doesn't seem to work properly.

On launch, only the Touch ID alert shows up, and the passcode screen doesn't.
On going to background, the passcode screen shows up in the task switcher, but when selecting the app, the screen goes away, and the Touch ID alert is not shown at all.

Seems like it's something window related. This is on iOS 11.1

App switcher screenshot

First of all thank you. This is a great project I really like it.
But I have a problem with the screenshot in the app switcher.
It only shows a white screen (not even the numpad).
I would like to show the user a picture instead of the white screen is this possible?
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.