Fix a bug about TOTP refresh

This commit is contained in:
Yishi Lin 2017-03-07 09:50:18 +08:00
parent af1ea3ee3e
commit 3cf88dcbc8
2 changed files with 26 additions and 10 deletions

View file

@ -170,20 +170,16 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
return
}
switch token.generator.factor {
case .counter:
// htop
break
case .timer(let period):
case .timer:
// totp
let timeSinceEpoch = Date().timeIntervalSince1970
let validTime = Int(period - timeSinceEpoch.truncatingRemainder(dividingBy: period))
strongSelf.tableData[indexPath.section].item[indexPath.row].title = "time-based (expiring in \(validTime)s)"
cell.cellData?.title = "time-based (valid within \(validTime)s)"
if validTime <= 1 || validTime >= Int(period - 1) {
let otp = token.currentPassword ?? "error"
if let (title, otp) = strongSelf.password?.getOtpStrings() {
strongSelf.tableData[indexPath.section].item[indexPath.row].title = title
strongSelf.tableData[indexPath.section].item[indexPath.row].content = otp
cell.cellData?.title = title
cell.cellData?.content = otp
}
default:
break
}
}
}