From 62a4188b848ebe7b28e6b04280344ef6b500cc62 Mon Sep 17 00:00:00 2001 From: Mayckon Date: Mon, 22 Apr 2019 11:11:18 +0200 Subject: [PATCH] bug fixed when start registered password --- Example/ViewController.swift | 16 +--------------- .../Classes/Protocols/MBSAuthenticatable.swift | 3 --- .../Classes/UI/MBSPasswordView.swift | 17 ++++++++++++++++- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Example/ViewController.swift b/Example/ViewController.swift index ffea2ed..701cb88 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -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() @@ -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") - - } - } } } } diff --git a/MBSPasswordView/Classes/Protocols/MBSAuthenticatable.swift b/MBSPasswordView/Classes/Protocols/MBSAuthenticatable.swift index e121b31..ca567e3 100644 --- a/MBSPasswordView/Classes/Protocols/MBSAuthenticatable.swift +++ b/MBSPasswordView/Classes/Protocols/MBSAuthenticatable.swift @@ -10,10 +10,7 @@ import Foundation import LocalAuthentication public enum MBSAuthenticationIDError: Error { - case notRegistered - case canceled case notSupported - case invalidID } public protocol MBSAuthenticatable { diff --git a/MBSPasswordView/Classes/UI/MBSPasswordView.swift b/MBSPasswordView/Classes/UI/MBSPasswordView.swift index b56e46e..a3ce3b6 100644 --- a/MBSPasswordView/Classes/UI/MBSPasswordView.swift +++ b/MBSPasswordView/Classes/UI/MBSPasswordView.swift @@ -135,7 +135,7 @@ extension MBSPasswordView: MBSTopPasswordDelegate, Shakable { public func password(_ result: [String]) { registerPassword(result) disableViews() - callBiometricsIfEnabled(result) + authenticateUser(result) } public func invalidMatch() { shakeView() @@ -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 {