diff --git a/pass/Controllers/PasswordEditorTableViewController.swift b/pass/Controllers/PasswordEditorTableViewController.swift index 3bcc0ac..ccd5b03 100644 --- a/pass/Controllers/PasswordEditorTableViewController.swift +++ b/pass/Controllers/PasswordEditorTableViewController.swift @@ -126,7 +126,23 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl } // generate password, copy to pasteboard, and set the cell + // check whether the current password looks like an OTP field func generateAndCopyPassword() { + if let currentPassword = fillPasswordCell?.getContent(), + Password.LooksLikeOTP(line: currentPassword) { + let alert = UIAlertController(title: "Overwrite?", message: "Overwrite the one-time password configuration?", preferredStyle: UIAlertControllerStyle.alert) + alert.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.destructive, handler: {_ in + self.generateAndCopyPasswordNoOtpCheck() + })) + alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil)) + self.present(alert, animated: true, completion: nil) + } else { + self.generateAndCopyPasswordNoOtpCheck() + } + } + + // generate the password, don't care whether the original line is otp + func generateAndCopyPasswordNoOtpCheck() { // show password settings (e.g., the length slider) if hidePasswordSettings == true { hidePasswordSettings = false diff --git a/pass/Models/Password.swift b/pass/Models/Password.swift index 32b029c..1d17846 100644 --- a/pass/Models/Password.swift +++ b/pass/Models/Password.swift @@ -76,7 +76,7 @@ class Password { // check whether the first line of the plainText looks like an otp entry let (key, value) = Password.getKeyValuePair(from: plainTextSplit[0]) - if key != nil && Password.otpKeywords.contains(key!) { + if Password.otpKeywords.contains(key ?? "") { firstLineIsOTPField = true self.additions[key!] = value self.additionKeys.insert(key!, at: 0) @@ -304,5 +304,8 @@ class Password { } } - + static func LooksLikeOTP(line: String) -> Bool { + let (key, _) = getKeyValuePair(from: line) + return Password.otpKeywords.contains(key ?? "") + } }