Support hiding one time password related fields.
- Add a switch to turn on/off one time password related fields. - Improve how we show the additional information
This commit is contained in:
parent
3dac155d6c
commit
f2edc2ffaa
4 changed files with 76 additions and 45 deletions
|
|
@ -19,6 +19,14 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
||||||
return uiSwitch
|
return uiSwitch
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
let hideOTPSwitch: UISwitch = {
|
||||||
|
let uiSwitch = UISwitch()
|
||||||
|
uiSwitch.onTintColor = Globals.blue
|
||||||
|
uiSwitch.sizeToFit()
|
||||||
|
uiSwitch.addTarget(self, action: #selector(hideOTPSwitchAction(_:)), for: UIControlEvents.valueChanged)
|
||||||
|
return uiSwitch
|
||||||
|
}()
|
||||||
|
|
||||||
let rememberPassphraseSwitch: UISwitch = {
|
let rememberPassphraseSwitch: UISwitch = {
|
||||||
let uiSwitch = UISwitch()
|
let uiSwitch = UISwitch()
|
||||||
uiSwitch.onTintColor = Globals.blue
|
uiSwitch.onTintColor = Globals.blue
|
||||||
|
|
@ -50,6 +58,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
||||||
[
|
[
|
||||||
[.title: "Show Folder", .action: "none",],
|
[.title: "Show Folder", .action: "none",],
|
||||||
[.title: "Hide Unknown Fields", .action: "none",],
|
[.title: "Hide Unknown Fields", .action: "none",],
|
||||||
|
[.title: "Hide One Time Password Fields", .action: "none",],
|
||||||
],
|
],
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
@ -72,6 +81,18 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
||||||
cell.accessoryView = accessoryView
|
cell.accessoryView = accessoryView
|
||||||
cell.selectionStyle = .none
|
cell.selectionStyle = .none
|
||||||
hideUnknownSwitch.isOn = Defaults[.isHideUnknownOn]
|
hideUnknownSwitch.isOn = Defaults[.isHideUnknownOn]
|
||||||
|
case "Hide One Time Password Fields":
|
||||||
|
cell.accessoryType = .none
|
||||||
|
let detailButton = UIButton(type: .detailDisclosure)
|
||||||
|
hideOTPSwitch.frame = CGRect(x: detailButton.bounds.width+10, y: 0, width: hideOTPSwitch.bounds.width, height: hideOTPSwitch.bounds.height)
|
||||||
|
detailButton.frame = CGRect(x: 0, y: 5, width: detailButton.bounds.width, height: detailButton.bounds.height)
|
||||||
|
detailButton.addTarget(self, action: #selector(GeneralSettingsTableViewController.tapHideOTPSwitchDetailButton(_:)), for: UIControlEvents.touchDown)
|
||||||
|
let accessoryView = UIView(frame: CGRect(x: 0, y: 0, width: detailButton.bounds.width + hideOTPSwitch.bounds.width+10, height: hideOTPSwitch.bounds.height))
|
||||||
|
accessoryView.addSubview(detailButton)
|
||||||
|
accessoryView.addSubview(hideOTPSwitch)
|
||||||
|
cell.accessoryView = accessoryView
|
||||||
|
cell.selectionStyle = .none
|
||||||
|
hideOTPSwitch.isOn = Defaults[.isHideOTPOn]
|
||||||
case "Remember Phassphrase":
|
case "Remember Phassphrase":
|
||||||
cell.accessoryType = .none
|
cell.accessoryType = .none
|
||||||
cell.selectionStyle = .none
|
cell.selectionStyle = .none
|
||||||
|
|
@ -91,10 +112,21 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
||||||
Utils.alert(title: alertTitle, message: alertMessage, controller: self, completion: nil)
|
Utils.alert(title: alertTitle, message: alertMessage, controller: self, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tapHideOTPSwitchDetailButton(_ sender: Any?) {
|
||||||
|
let keywordsString = Password.otpKeywords.joined(separator: ",")
|
||||||
|
let alertMessage = "Turn on this switch to hide the fields related to one time passwords (i.e., \(keywordsString))."
|
||||||
|
let alertTitle = "Hide One Time Password Fields"
|
||||||
|
Utils.alert(title: alertTitle, message: alertMessage, controller: self, completion: nil)
|
||||||
|
}
|
||||||
|
|
||||||
func hideUnknownSwitchAction(_ sender: Any?) {
|
func hideUnknownSwitchAction(_ sender: Any?) {
|
||||||
Defaults[.isHideUnknownOn] = hideUnknownSwitch.isOn
|
Defaults[.isHideUnknownOn] = hideUnknownSwitch.isOn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hideOTPSwitchAction(_ sender: Any?) {
|
||||||
|
Defaults[.isHideOTPOn] = hideOTPSwitch.isOn
|
||||||
|
}
|
||||||
|
|
||||||
func rememberPassphraseSwitchAction(_ sender: Any?) {
|
func rememberPassphraseSwitchAction(_ sender: Any?) {
|
||||||
Defaults[.isRememberPassphraseOn] = rememberPassphraseSwitch.isOn
|
Defaults[.isRememberPassphraseOn] = rememberPassphraseSwitch.isOn
|
||||||
if rememberPassphraseSwitch.isOn == false {
|
if rememberPassphraseSwitch.isOn == false {
|
||||||
|
|
|
||||||
|
|
@ -199,20 +199,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
||||||
self.tableData[tableDataIndex].item.append(TableCell(title: "username", content: username))
|
self.tableData[tableDataIndex].item.append(TableCell(title: "username", content: username))
|
||||||
}
|
}
|
||||||
self.tableData[tableDataIndex].item.append(TableCell(title: "password", content: password.password))
|
self.tableData[tableDataIndex].item.append(TableCell(title: "password", content: password.password))
|
||||||
// Show additional information
|
|
||||||
if password.additions.count > 0 {
|
|
||||||
self.tableData.append(TableSection(title: "additions", item: []))
|
|
||||||
tableDataIndex += 1
|
|
||||||
for additionKey in password.additionKeys {
|
|
||||||
if (!additionKey.hasPrefix("unknown") || !Defaults[.isHideUnknownOn]) &&
|
|
||||||
additionKey.lowercased() != "username" &&
|
|
||||||
additionKey.lowercased() != "password" {
|
|
||||||
self.tableData[tableDataIndex].item.append(TableCell(title: additionKey, content: password.additions[additionKey]!))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Show one time password
|
// Show one time password
|
||||||
if password.otpType == "totp", password.otpToken != nil {
|
if password.otpType == "totp", password.otpToken != nil {
|
||||||
self.tableData.append(TableSection(title: "One time password (TOTP)", item: []))
|
self.tableData.append(TableSection(title: "One time password (TOTP)", item: []))
|
||||||
|
|
@ -221,6 +208,21 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
|
||||||
self.tableData[tableDataIndex].item.append(TableCell(title: "current", content: crtPassword))
|
self.tableData[tableDataIndex].item.append(TableCell(title: "current", content: crtPassword))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show additional information
|
||||||
|
let filteredAdditionKeys = password.additionKeys.filter {
|
||||||
|
$0.lowercased() != "username" &&
|
||||||
|
$0.lowercased() != "password" &&
|
||||||
|
(!$0.hasPrefix("unknown") || !Defaults[.isHideOTPOn]) &&
|
||||||
|
(!Password.otpKeywords.contains($0) || !Defaults[.isHideOTPOn]) }
|
||||||
|
|
||||||
|
if filteredAdditionKeys.count > 0 {
|
||||||
|
self.tableData.append(TableSection(title: "additions", item: []))
|
||||||
|
tableDataIndex += 1
|
||||||
|
for additionKey in filteredAdditionKeys {
|
||||||
|
self.tableData[tableDataIndex].item.append(TableCell(title: additionKey, content: password.additions[additionKey]!))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ extension DefaultsKeys {
|
||||||
static let passcodeKey = DefaultsKey<String?>("passcodeKey")
|
static let passcodeKey = DefaultsKey<String?>("passcodeKey")
|
||||||
|
|
||||||
static let isHideUnknownOn = DefaultsKey<Bool>("isHideUnknownOn")
|
static let isHideUnknownOn = DefaultsKey<Bool>("isHideUnknownOn")
|
||||||
|
static let isHideOTPOn = DefaultsKey<Bool>("isHideOTPOn")
|
||||||
static let isRememberPassphraseOn = DefaultsKey<Bool>("isRememberPassphraseOn")
|
static let isRememberPassphraseOn = DefaultsKey<Bool>("isRememberPassphraseOn")
|
||||||
static let isShowFolderOn = DefaultsKey<Bool>("isShowFolderOn")
|
static let isShowFolderOn = DefaultsKey<Bool>("isShowFolderOn")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,22 @@ class Password {
|
||||||
var additionKeys = [String]()
|
var additionKeys = [String]()
|
||||||
var plainText = ""
|
var plainText = ""
|
||||||
var changed = false
|
var changed = false
|
||||||
|
var firstLineIsOTPField = false
|
||||||
var otpType: String?
|
var otpType: String?
|
||||||
var otpToken: Token?
|
var otpToken: Token?
|
||||||
|
|
||||||
init(name: String, plainText: String) {
|
init(name: String, plainText: String) {
|
||||||
|
self.initEverything(name: name, plainText: plainText)
|
||||||
|
}
|
||||||
|
|
||||||
|
func updatePassword(name: String, plainText: String) {
|
||||||
|
if self.plainText != plainText {
|
||||||
|
self.initEverything(name: name, plainText: plainText)
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func initEverything(name: String, plainText: String) {
|
||||||
self.name = name
|
self.name = name
|
||||||
self.plainText = plainText
|
self.plainText = plainText
|
||||||
|
|
||||||
|
|
@ -42,8 +54,11 @@ class Password {
|
||||||
// check whether the first line of the plainText looks like an otp entry
|
// check whether the first line of the plainText looks like an otp entry
|
||||||
let (key, value) = Password.getKeyValuePair(from: plainTextSplit[0])
|
let (key, value) = Password.getKeyValuePair(from: plainTextSplit[0])
|
||||||
if key != nil && Password.otpKeywords.contains(key!) {
|
if key != nil && Password.otpKeywords.contains(key!) {
|
||||||
|
firstLineIsOTPField = true
|
||||||
self.additions[key!] = value
|
self.additions[key!] = value
|
||||||
self.additionKeys.append(key!)
|
self.additionKeys.insert(key!, at: 0)
|
||||||
|
} else {
|
||||||
|
firstLineIsOTPField = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// construct the otp token
|
// construct the otp token
|
||||||
|
|
@ -94,39 +109,20 @@ class Password {
|
||||||
return (additions, additionKeys)
|
return (additions, additionKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updatePassword(name: String, plainText: String) {
|
func getAdditionsPlainText() -> String {
|
||||||
self.name = name
|
// lines starting from the second
|
||||||
if self.plainText != plainText {
|
|
||||||
self.name = name
|
|
||||||
self.plainText = plainText
|
|
||||||
|
|
||||||
// get password and additional fields
|
|
||||||
let plainTextSplit = plainText.characters.split(maxSplits: 1, omittingEmptySubsequences: false) {
|
let plainTextSplit = plainText.characters.split(maxSplits: 1, omittingEmptySubsequences: false) {
|
||||||
$0 == "\n" || $0 == "\r\n"
|
$0 == "\n" || $0 == "\r\n"
|
||||||
}.map(String.init)
|
}.map(String.init)
|
||||||
self.password = plainTextSplit[0]
|
if plainTextSplit.count == 1 {
|
||||||
(self.additions, self.additionKeys) = Password.getAdditionFields(from: plainTextSplit[1])
|
return ""
|
||||||
|
|
||||||
// construct the otp token
|
|
||||||
self.updateOtpToken()
|
|
||||||
|
|
||||||
changed = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getAdditionsPlainText() -> String {
|
|
||||||
let plainAdditionsText = self.additionKeys.map {
|
|
||||||
if $0.hasPrefix("unknown") {
|
|
||||||
return "\(self.additions[$0]!)"
|
|
||||||
} else {
|
} else {
|
||||||
return "\($0): \(self.additions[$0]!)"
|
return plainTextSplit[1]
|
||||||
}
|
}
|
||||||
}.joined(separator: "\n")
|
|
||||||
return plainAdditionsText
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPlainText() -> String {
|
func getPlainText() -> String {
|
||||||
return "\(self.password)\n\(getAdditionsPlainText())"
|
return self.plainText
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPlainData() -> Data {
|
func getPlainData() -> Data {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue