An advanced Ethereum/EVM mobile wallet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
alpha-wallet-ios/Trust/Lock/Lock.swift

41 lines
1.4 KiB

// Copyright SIX DAY LLC. All rights reserved.
import UIKit
import SSKeychain
class Lock {
private struct Keys {
static let service = "trust.lock"
static let account = "trust.account"
}
private let standardDefaults = UserDefaults.standard
private let passcodeAttempts = "passcodeAttempts"
func isPasscodeSet() -> Bool {
return currentPasscode() != nil
}
func currentPasscode() -> String? {
return SSKeychain.password(forService: Keys.service, account: Keys.account)
}
func isPasscodeValid(passcode: String) -> Bool {
return passcode == currentPasscode()
}
func setPasscode(passcode: String) {
SSKeychain.setPassword(passcode, forService: Keys.service, account: Keys.account)
}
func deletePasscode() {
SSKeychain.deletePassword(forService: Keys.service, account: Keys.account)
resetPasscodeAttemptHistory()
}
func numberOfAttempts() -> Int {
return standardDefaults.integer(forKey: passcodeAttempts)
}
func resetPasscodeAttemptHistory() {
standardDefaults.removeObject(forKey: passcodeAttempts)
}
func recordIncorrectPasscodeAttempt() {
var numberOfAttemptsSoFar = standardDefaults.integer(forKey: passcodeAttempts)
numberOfAttemptsSoFar += 1
standardDefaults.set(passcodeAttempts, forKey: passcodeAttempts)
}
}