BasePassCodeService added
This commit is contained in:
parent
6f1ec15d48
commit
6efc671aea
|
|
@ -18,6 +18,7 @@
|
|||
EF05EDC11EAF706200CAE7B6 /* BaseDateFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDBE1EAF706200CAE7B6 /* BaseDateFormatter.swift */; };
|
||||
EF05EDC21EAF706200CAE7B6 /* DefaultNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDBF1EAF706200CAE7B6 /* DefaultNetworkService.swift */; };
|
||||
EF05EDC61EAF70EB00CAE7B6 /* TouchIDService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDC51EAF70EB00CAE7B6 /* TouchIDService.swift */; };
|
||||
EF05EDC81EAF91D500CAE7B6 /* BasePassCodeService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDC71EAF91D500CAE7B6 /* BasePassCodeService.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
|
|
@ -36,6 +37,7 @@
|
|||
EF05EDBE1EAF706200CAE7B6 /* BaseDateFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseDateFormatter.swift; sourceTree = "<group>"; };
|
||||
EF05EDBF1EAF706200CAE7B6 /* DefaultNetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultNetworkService.swift; sourceTree = "<group>"; };
|
||||
EF05EDC51EAF70EB00CAE7B6 /* TouchIDService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TouchIDService.swift; sourceTree = "<group>"; };
|
||||
EF05EDC71EAF91D500CAE7B6 /* BasePassCodeService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasePassCodeService.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
|
@ -102,6 +104,7 @@
|
|||
CAE698F31E968E28000394B0 /* Services */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
EF05EDC71EAF91D500CAE7B6 /* BasePassCodeService.swift */,
|
||||
EF05EDB31EAF703A00CAE7B6 /* BaseUserService.swift */,
|
||||
EF05EDC51EAF70EB00CAE7B6 /* TouchIDService.swift */,
|
||||
);
|
||||
|
|
@ -288,6 +291,7 @@
|
|||
EF05EDC01EAF706200CAE7B6 /* ApiResponse.swift in Sources */,
|
||||
EF05EDBC1EAF705500CAE7B6 /* ConnectionError.swift in Sources */,
|
||||
EF05EDB41EAF703A00CAE7B6 /* BaseUserService.swift in Sources */,
|
||||
EF05EDC81EAF91D500CAE7B6 /* BasePassCodeService.swift in Sources */,
|
||||
EF05EDC11EAF706200CAE7B6 /* BaseDateFormatter.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,99 @@
|
|||
//
|
||||
// Copyright (c) 2017 Touch Instinct
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
import KeychainAccess
|
||||
import CocoaLumberjack
|
||||
|
||||
open class BasePassCodeService {
|
||||
|
||||
open class var keychainService: String {
|
||||
return Bundle.main.bundleIdentifier ?? ""
|
||||
}
|
||||
|
||||
public init() {
|
||||
let isInitialLoad = UserDefaults.standard.bool(forKey: Keys.isInitialLoad)
|
||||
if isInitialLoad {
|
||||
UserDefaults.standard.set(false, forKey: Keys.isInitialLoad)
|
||||
reset()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private stuff
|
||||
|
||||
fileprivate lazy var keychain: Keychain = {
|
||||
return Keychain(service: keychainService)
|
||||
.synchronizable(false)
|
||||
}()
|
||||
|
||||
fileprivate var passCodeHash: String? {
|
||||
return keychain[Keys.passCodeHash]
|
||||
}
|
||||
|
||||
fileprivate enum Keys {
|
||||
static let passCodeHash = "passCodeHash"
|
||||
static let isTouchIdEnabled = "isTouchIdEnabled"
|
||||
static let isInitialLoad = "isInitialLoad"
|
||||
}
|
||||
|
||||
fileprivate enum Values {
|
||||
static let touchIdEnabled = "touchIdEnabled"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension BasePassCodeService {
|
||||
|
||||
public var isPassCodeSaved: Bool {
|
||||
return keychain[Keys.passCodeHash] != nil
|
||||
}
|
||||
|
||||
public var isTouchIdEnabled: Bool {
|
||||
get {
|
||||
return keychain[Keys.isTouchIdEnabled] == Values.touchIdEnabled
|
||||
}
|
||||
set {
|
||||
keychain[Keys.isTouchIdEnabled] = newValue ? Values.touchIdEnabled : nil
|
||||
}
|
||||
}
|
||||
|
||||
public func save(passCode: String?) {
|
||||
keychain[Keys.passCodeHash] = passCode?.hashMD5
|
||||
}
|
||||
|
||||
public func check(passCode: String) -> Bool {
|
||||
return passCode.hashMD5 == passCodeHash
|
||||
}
|
||||
|
||||
public func reset() {
|
||||
save(passCode: nil)
|
||||
isTouchIdEnabled = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension String {
|
||||
|
||||
var hashMD5: String? {
|
||||
return self
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ target 'LeadKitAdditions' do
|
|||
|
||||
pod 'LeadKit', :git => 'https://github.com/TouchInstinct/LeadKit.git', :branch => 'fix/sharedApplication', :commit => 'fd0eb18b8a6680ff16bbb1668d1ae0d29f29fad7'
|
||||
pod 'TableKit'
|
||||
pod 'KeychainAccess'
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ PODS:
|
|||
- CocoaLumberjack/Default (3.1.0)
|
||||
- CocoaLumberjack/Swift (3.1.0):
|
||||
- CocoaLumberjack/Default
|
||||
- KeychainAccess (3.0.2)
|
||||
- LeadKit (0.4.6):
|
||||
- CocoaLumberjack/Swift (~> 3.1.0)
|
||||
- ObjectMapper (~> 2.1)
|
||||
|
|
@ -23,6 +24,7 @@ PODS:
|
|||
- Toast-Swift (2.0.0)
|
||||
|
||||
DEPENDENCIES:
|
||||
- KeychainAccess
|
||||
- LeadKit (from `https://github.com/TouchInstinct/LeadKit.git`, commit `fd0eb18b8a6680ff16bbb1668d1ae0d29f29fad7`, branch `fix/sharedApplication`)
|
||||
- TableKit
|
||||
|
||||
|
|
@ -40,6 +42,7 @@ CHECKOUT OPTIONS:
|
|||
SPEC CHECKSUMS:
|
||||
Alamofire: dc44b1600b800eb63da6a19039a0083d62a6a62d
|
||||
CocoaLumberjack: 8311463ddf9ee86a06ef92a071dd656c89244500
|
||||
KeychainAccess: a986406022dfc7c634c691ad3bec670cc6a32002
|
||||
LeadKit: d688a8bef79de7bbd83d553da3cb6c5292d48f2d
|
||||
ObjectMapper: fb30f71e08470d1e5a20b199fafe1246281db898
|
||||
RxAlamofire: 0b1fa48f545fffe7f7a28af2086bcaa3b5946cc9
|
||||
|
|
@ -48,6 +51,6 @@ SPEC CHECKSUMS:
|
|||
TableKit: 02e041b443f75fa3e9f1ee6024d4b256305bd904
|
||||
Toast-Swift: 5b2f8f720f7e78e48511f693df1f9c9a6e38a25a
|
||||
|
||||
PODFILE CHECKSUM: ce4fe179e6470b751617d19baacbce25502a7002
|
||||
PODFILE CHECKSUM: f6bfca600b479c264f39b85593af2629edff3515
|
||||
|
||||
COCOAPODS: 1.2.1
|
||||
|
|
|
|||
Loading…
Reference in New Issue