Swift:
class AXPassword {
private var isOpen: Bool = false
private var maxAttempts: Int = 3
private var loginAttempts: Int = maxAttempts
private var regexUtil: RegexUtil = RegexUtil()
private var code: Int = 0
func codeUpdate(ear: String) -> Bool {
if !isOpen {
return false
}
if ear.contains("code") {
let temp = regexUtil.extractRegex(enumRegexGrimoire.integer, ear)
if !temp.isEmpty() {
code = Int(temp)!
return true
}
}
return false
}
func openGate(ear: String) {
if ear.contains("code") && loginAttempts > 0 {
let noCode = regexUtil.extractRegex(enumRegexGrimoire.integer, ear)
if noCode.isEmpty() {
return
}
let tempCode = Int(noCode)!
if tempCode == code {
loginAttempts = maxAttempts
isOpen = true
} else {
loginAttempts -= 1
}
}
}
func isOpen() -> Bool {
return isOpen
}
func resetAttempts() {
loginAttempts = maxAttempts
}
func getLoginAttempts() -> Int {
return loginAttempts
}
func closeGate() {
isOpen = false
}
func closeGate(ear: String) {
if ear.contains("close") {
isOpen = false
}
}
func setMaxAttempts(maxAttempts: Int) {
self.maxAttempts = maxAttempts
}
func getCode() -> Int {
if isOpen {
return code
}
return -1
}
func randomizeCode(lim: Int, minimumLim: Int) {
code = DrawRnd().getSimpleRNDNum(lim) + minimumLim
}
func getCodeEvent() -> Int {
return code
}
}