Skip to content

Commit

Permalink
bug fixed when start registered password
Browse files Browse the repository at this point in the history
  • Loading branch information
mayckonx committed Apr 22, 2019
1 parent e8af4d2 commit 62a4188
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
16 changes: 1 addition & 15 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class ViewController: UIViewController {

passwordView?.delegate = self
passwordView?.titleToRequestAuthentication = "Please, identify your self!"
passwordView?.start(enableBiometrics: false)
passwordView?.changeExistingPassword()
passwordView?.start(enableBiometrics: true)

// when user wants to change the registered password... you just use this method and mbspasswordview will take care of it and gives you the new password on the password delegate method.
//passwordView?.changeExistingPassword()
Expand Down Expand Up @@ -58,19 +57,6 @@ extension ViewController: MBSPasswordDelegate {
print("Authenticated by password and biometrics. Password:\(password)")
case .error(let error):
print("Error to authenticate by biometrics...")
if let error = (error as? MBSAuthenticationIDError) {
switch error {
case .notRegistered:
print("notRegistered")
case .invalidID:
print("invalidID")
case .notSupported:
print("device or so notSupported")
case .canceled:
print("canceled")

}
}
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions MBSPasswordView/Classes/Protocols/MBSAuthenticatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import Foundation
import LocalAuthentication

public enum MBSAuthenticationIDError: Error {
case notRegistered
case canceled
case notSupported
case invalidID
}

public protocol MBSAuthenticatable {
Expand Down
17 changes: 16 additions & 1 deletion MBSPasswordView/Classes/UI/MBSPasswordView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ extension MBSPasswordView: MBSTopPasswordDelegate, Shakable {
public func password(_ result: [String]) {
registerPassword(result)
disableViews()
callBiometricsIfEnabled(result)
authenticateUser(result)
}
public func invalidMatch() {
shakeView()
Expand Down Expand Up @@ -287,6 +287,21 @@ extension MBSPasswordView {
// MARK: - Request Authentication
extension MBSPasswordView: MBSAuthenticatable {
private func callBiometricsIfEnabled(_ password: [String]) {
if enableBiometricsAuthentication {
self.authenticateByBiometrics(title: titleToRequestAuthentication) { result in
switch result {
case .success:
self.delegate?.passwordFromBiometrics(MBSPasswordResult.success(password))
case .error(let error):
// we won't request on the next try... User should try by password
self.enableBiometricsAuthentication = false
self.delegate?.passwordFromBiometrics(MBSPasswordResult.error(error))
}
}
}
}

private func authenticateUser(_ password: [String]) {
if enableBiometricsAuthentication {
self.authenticateByBiometrics(title: titleToRequestAuthentication) { result in
switch result {
Expand Down

0 comments on commit 62a4188

Please sign in to comment.