yankodimitrov / swiftpasscodelock Goto Github PK
View Code? Open in Web Editor NEWAn iOS passcode lock with TouchID authentication written in Swift.
License: MIT License
An iOS passcode lock with TouchID authentication written in Swift.
License: MIT License
I want to know when passcodeLockDidSucceed happens. I tried adding PasscodeLockTypeDelegate to my viewController, but for some reason none of these delegate functions are being triggered:
func passcodeLockDidSucceed(lock: PasscodeLockType)
func passcodeLockDidFail(lock: PasscodeLockType)
func passcodeLockDidChangeState(lock: PasscodeLockType)
func passcodeLock(lock: PasscodeLockType, addedSignAtIndex index: Int)
func passcodeLock(lock: PasscodeLockType, removedSignAtIndex index: Int)
Hi, i tried importing your project into mine.
When i open PasscodeView.xib it gives my 70 warnings.
PasscodeView.xib: warning: IB Designables: Ignoring user defined runtime attribute for key path "activeColor" on instance of "UIView". Hit an exception when attempting to set its value: [<UIView 0x7fd81acd87d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key activeColor.
I tried finding a solution on google, but i couldn't find one, maybe you know the answer?
Please reply soon, thanks in advance.
Thomas
I made a translation of PasscodeLock.strings to Russian, but found that "Cancel" and "Delete" buttons on keypad are still in English. It's strange that this behavior hasn't got an attention yet. Localization should be supported for them. However, there is a workaround using custom PasscodeLockViewController:
class LocalizedPasscodeViewController: PasscodeLockViewController {
override func viewDidLoad() {
super.viewDidLoad()
cancelButton?.setTitle(NSLocalizedString("passcode_cancel_button", comment: "Passcode screen cancel button"), forState: .Normal)
deleteSignButton?.setTitle(NSLocalizedString("passcode_delete_button", comment: "Passcode screen delete button"), forState: .Normal)
}
}
Hello,
Just wonder if this possible, it is a bit annoy when every time user open app, a touchID pop up appear
Thanks.
When I leave an alertcontroller open and close the app or leave the phone in standby, when I return to the app and unlock it, the alertcontroller is misplaced in top of the screen.
This happens for all the alertcontrollers.
It might be helpful to make PasscodeViewController
a singleton so as we can easily ask for the Lock screen in a single line when needed.
Also it will be easier to support methods like isLockscreenDisplayed
.
All this are easy to be handled in an app, but I was wondering if you like them in the lib, so as it will be easier for smaller projects to handle things.
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?
I installed the Carthage of PasscodeLock in my project (xcode 8.0 swift 3.0.1) , i update my xcode 8.0 to xcode 8.3 . Now it showing the error "module compiled with swift 3.0.1 cannot be imported in swift 3.1 "
Now I have another error with custom PasscodeLockView.xib when tap on on any number
fatal error: NSArray element failed to match the Swift Array Element type
Install from cocoapods and add PasscodeSignButton.swift, PasscodeSignPlaceholderView.swift files to project
I can't install from carthage, got a many errors like
could not build module 'UIKit'
I have been working in a project and I used this library for passcode lock. It is running smoothly in iOS 8. But when I try to change the device to IOS 7, app is crashed in this line :
let context = LAContext - (PasscodeViewController) due to no support for iOS 7. So what is the strategy that I could use instead?
Great repository, thanks for sharing! ๐
Do you have any plans for supporting passcodes longer than 4 digits? i.e. would be great.
If not, do you want to give me some pointers on how to do it?
Thanks!
:panos
SVProgressHUD shows the hud on UIWindowLevelNormal (which is 0). So, if we pass the app's main window to PasscodeLockPresenter(mainWindow:configuration:), its window level will be set (by PasscodeLockPresenter) to 1, causing SVProgressHUD never displays.
And if we pass nil, passcodeLockWindow will keep covering the app's main window after dismissing, make everything untouchable.
Here is my workaround, for your information:
public func presentPasscodeLock() {
guard passcodeConfiguration.repository.hasPasscode else { return }
guard !isPasscodePresented else { return }
isPasscodePresented = true
passcodeLockWindow.windowLevel = 2
passcodeLockWindow.hidden = false // add this line
let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode, configuration: passcodeConfiguration)
passcodeLockVC.dismissCompletionCallback = { [weak self] in
self?.dismissPasscodeLock()
}
passcodeLockWindow.rootViewController = passcodeLockVC
}
private func dismissPasscodeLock() {
isPasscodePresented = false
mainWindow?.windowLevel = 1
mainWindow?.makeKeyAndVisible()
UIView.animateWithDuration(
0.5,
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 0,
options: [.CurveEaseInOut],
animations: { [weak self] in
self?.passcodeLockWindow.alpha = 0
},
completion: { [weak self] _ in
self?.passcodeLockWindow.windowLevel = 0
self?.passcodeLockWindow.rootViewController = nil
self?.passcodeLockWindow.alpha = 1
self?.passcodeLockWindow.hidden = true // add this line
}
)
}
Hi,
Excellent work.
Can I use this with my Objective-C project?
Thanks.
I have opened the app and I got the following error:
Module file was created by an older version of the compiler; rebuild 'PasscodeLock' and try again: /Users/UserName/Documents/xcode/AppName/AppName/PasscodeLock.framework/Modules/PasscodeLock.swiftmodule/i386.swiftmodule
So I try to rebuild doing this:
carthage update
But I got the following errors:
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/Views/PasscodeSignButton.swift:74:33: warning: use '#selector' instead of explicitly constructing a 'Selector'
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/Views/PasscodeSignButton.swift:75:33: warning: use '#selector' instead of explicitly constructing a 'Selector'
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/PasscodeLockViewController.swift:110:57: warning: use of string literal for Objective-C selectors is deprecated; use '#selector' instead
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/PasscodeLockViewController.swift:111:57: warning: use of string literal for Objective-C selectors is deprecated; use '#selector' instead
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/Views/PasscodeSignButton.swift:74:33: warning: use '#selector' instead of explicitly constructing a 'Selector'
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/Views/PasscodeSignButton.swift:75:33: warning: use '#selector' instead of explicitly constructing a 'Selector'
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/PasscodeLockViewController.swift:110:57: warning: use of string literal for Objective-C selectors is deprecated; use '#selector' instead
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/PasscodeLockViewController.swift:111:57: warning: use of string literal for Objective-C selectors is deprecated; use '#selector' instead
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/Views/PasscodeSignButton.swift:74:33: warning: use '#selector' instead of explicitly constructing a 'Selector'
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/Views/PasscodeSignButton.swift:75:33: warning: use '#selector' instead of explicitly constructing a 'Selector'
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/PasscodeLockViewController.swift:110:57: warning: use of string literal for Objective-C selectors is deprecated; use '#selector' instead
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/PasscodeLockViewController.swift:111:57: warning: use of string literal for Objective-C selectors is deprecated; use '#selector' instead
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/Views/PasscodeSignButton.swift:74:33: warning: use '#selector' instead of explicitly constructing a 'Selector'
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/Views/PasscodeSignButton.swift:75:33: warning: use '#selector' instead of explicitly constructing a 'Selector'
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/PasscodeLockViewController.swift:110:57: warning: use of string literal for Objective-C selectors is deprecated; use '#selector' instead
/Users/UserName/Documents/xcode/AppName/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/PasscodeLockViewController.swift:111:57: warning: use of string literal for Objective-C selectors is deprecated; use '#selector' instead
When presenting PasscodeLock in AppDelegate applicationWillEnterForeground:
lazy var passcodeLockPresenter: PasscodeLockPresenter = {
let configuration = PasscodeLockConfiguration()
let presenter = PasscodeLockPresenter(mainWindow:self.window, configuration:configuration)
return presenter
}()
func applicationWillEnterForeground(application: UIApplication) {
passcodeLockPresenter.presentPasscodeLock()
}
the UIViewController that was present before entering background appears. Is it possible to present PasscodeLock without animation and avoid appearing of that UIViewController?
Thanks!
@antonigiske
@ziogaschr
@szappanyos
@yankodimitrov
@maximbilan
It would be great to see this implemented with keychain
Any option for this code in objective-C
I'm displaying the passcode presenter if touchID is not available and if the passcode is successfully entered I want to login to my parse database using the keychain username and password stored.
But if the passcode is not entered correctly I don't want to login using the keychain information.
After passcodeLockPresenter.presentPasscodeLock()
How do I verify if it was successfully entered or not?
When a passcode is set, and you start the app, the following warning appears in the console:
2015-09-03 08:31:41.141 PasscodeLockDemo[2751:663098] Unbalanced calls to begin/end appearance transitions for <UIViewController: 0x12f6517b0>.
After doing some research, this issue is caused from line 21 on the PasscodeLockPresenter.swift file. When creating a UIViewController() w/o specifying the nib file to pass in to the initializer, it is causing an animation when it's added to the window, but there are other animations already currently taking place via the normal startup means on the mainWindow object (best I can tell.)
Can we have a pre-set password that the developers sets instead of having the user set it to make the app accessible to few people?
I noticed that PasscodeLock adds a new UIVisualEffectView each time the passcodes don't match, which means that if I fail to match the passcodes while setting a new passcode the app will keep adding subviews until it runs out of memory.
Can you please check it out?
Thanks.
I built a very simple Keychain based repository for PasscodeRepositoryType.
https://gist.github.com/kristofer/9ce4ebce33a90dc080e4ba2c8b659d1c
// KeychainPasscodeRepository.swift
// PasscodeLock
// a simple example of a keychain based repository for
// https://github.com/yankodimitrov/SwiftPasscodeLock
// uses this fine work for easy access to Keychain
// https://cocoapods.org/pods/KeychainAccess
feel free to close this issue, Yanko
Hi, great framework, its the only one that was able to work nicely. However, I am facing an issue with the code found in the app delegate, its preventing my SVProgressHUD from displaying anywhere on the app. Any ideas on why this is so? I used the same code from the example project in the app delegate:
import PasscodeLock
//PassCode Lock Code
lazy var passcodeLockPresenter: PasscodeLockPresenter = {
let configuration = PasscodeLockConfiguration()
let presenter = PasscodeLockPresenter(mainWindow: self.window, configuration: configuration)
return presenter
}()
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
passcodeLockPresenter.present()
return true
}
func applicationDidEnterBackground(_ application: UIApplication) {
passcodeLockPresenter.present()
}
I don't now if this is an Xcode 7 beta issue, or if I'm the only one... But when I tried implementing a custom xib file, as described here:
"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"
Interface Builder couldn't/wouldn't recognize the PasscodeSignPlaceholderView or PasscodeSignButton classes when I tried associating them with UIButtons, UIViews, etc.
The code signing identity on the project is set, would probably be better to set it to none so it runs out of the box
There is no reference to PasscodeLockPresenter
. It might be nice to include it in the UML.
Have you found an automated way for creating the UMLs in Xcode?
Hi there,
I was just testing your app. it's pretty awesome :)
In the demo, when I run the app, set a passcode, close the app, type in my passcode and then click the switch to turn the passcode off the screen pops up to type my passcode in. When I do that (type in the passcode), nothing happens . The screen just stays there and I have to click cancel. When the view closes.
Any Ideas?
One issue we have found is that after entering an incorrect PIN, there is some issues with which placeholder is shown highlighted. If the user taps quickly on another number button after entering the fourth key, the animation shows the first placeholder show highlighted during the animation, then when another selection is made after the animation the second placeholder is highlighted, and the first is not. Issue is that even though there is a check to enter the text until after the animation you need to first disable after an entry, and keep it disabled until after the animation when the 4th character is entered.
I've been having issues installing this with carthage. The files download to /Checkouts but then fails to build:
** BUILD FAILED **
The following build commands failed:
CompileSwift normal x86_64 /Users/Christo/Developer/Screen/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/PasscodeLock/SetPasscodeState.swift
CompileSwift normal x86_64 /Users/Christo/Developer/Screen/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/PasscodeLock/ChangePasscodeState.swift
CompileSwift normal x86_64 /Users/Christo/Developer/Screen/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift
CompileSwift normal x86_64 /Users/Christo/Developer/Screen/Carthage/Checkouts/SwiftPasscodeLock/PasscodeLock/Views/PasscodeSignPlaceholderView.swift
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(5 failures)
Any ideas?
Please add CocoaPods support. Thank you.
Hi,
This bug allows to brute force the passcode lock by quitting the app before reaching the maximum attempts limit and then opening the app again.
A solution could be to store the value in the NSUserDefaults or the Keychain.
When I do a carthage update right now against your repo it tells me:
No tagged versions found for github "yankodimitrov/SwiftPasscodeLock"
I believe you need to tag/create a release
Hi
How to use the touch ID functionality with the passcode. Any help is much appreciated.
Thanks
Scenario:
When user logs in and set the passcode, then logs out and app deletes the passcode from defaults, if user closes and opens the app, biometrics authentication is presented. It can be canceled and user can continue using the app.
Fixable by:
private func authenticateWithBiometrics() {
if !self.passcodeConfiguration.repository.hasPasscode { return }
if passcodeConfiguration.shouldRequestTouchIDImmediately && passcodeLock.isTouchIDAllowed {
passcodeLock.authenticateWithBiometrics()
}
}
If I toggle the passcode switch to 'on', set a passcode, and then leave the app. Upon returning, I'm greeted with the new passcode, but no touchID authentication modal. I have to kill the app, and then enter it to get the touchID authentication modal to present.
@ziogaschr, @waltermvp, @venj, @kiokumicu, @guidelfrate, @gblotter, @karlml, @twofish187
Look guys, I just don't know what's happened with @yankodimitrov and I hope that everything is just going fine and he simply became very-very rich and threw out his laptop
But anyway, this great project needs an evolution, so I propose to continue work on this project somewhere else
I've made a fork of this project and merged a @ziogaschr outstanding commits into it, so you can fork it and start to make things happen
Thank you
Add the option to specify the maximum number of attempts M
to enter a PIN. If specified, and when this number of attempts M
is reached, the App will be informed of this. In our app, we would e.g. erase the App data.
Nice to have: option to additionally specify the number of attempts N
after which new PIN entry will be disabled for 2^(A-N+1)
seconds - i.e. with exponential back off - where A
is the current attempt.
I have the need to set a successCallback
to PasscodeLockViewController
.
I see that there are two options:
public var successCallback: ((lock: PasscodeLockType) -> Void)?
which is then set as passcodeLockVC.successCallback
passcodeLockVC
a public var.p.s.: Why the successCallback
passes the lock: PasscodeLockType
. Can you give me a good example? I might benefit from that.
By default .SetPasscode state has the cancel button. But in .EnterPasscode state cancel button is missing. Is there a simple way to enable cancel button in .EnterPasscode state?
Awesome lib!
Thanks!
@ziogaschr , @szappanyos , @yankodimitrov , @maximbilan , @gblotter
First of all, great stuff!
Second, I have the scenario where a user reaches the max number of passcode attempts.
When this happens, I want to delete all the sensitive information of the app and destroy the PasscodeViewController.
How can I do the latter?
Thanks!
:panos
Hello
great app its amazing
but I'mfacing a prob when i want to add a background image to PasscodeLockView.xib it wont appear when i run the project and it says in the debugger description could not load "background image referenced from a nib in the bundle with identifier .....
any clue how to show the background image.
thank you
/MM
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 ?
The text with keyboard is not working.
When i return the screen is locked but the keyboard is visible.
Could there be an option or enum to edit the xib statusbar color as well for dark backgrounds?
Currently an option that exists is to use a function like the one below for the view controller, which is ok for a temporary solution
override public func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent
}
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 at run time the reason that will show up when TouchId is triggered. 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.
I just need to add a parent passcode to open the app then I have some separate folder inside and want to set different-different passcode for each folder.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.