Add option to select two flavors of password generator: random and apple's (keychain)
This commit is contained in:
parent
3cf88dcbc8
commit
ad0c39b541
5 changed files with 59 additions and 11 deletions
|
|
@ -33,6 +33,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
self.perform(#selector(postSearchNotification), with: nil, afterDelay: 0.4)
|
||||
}
|
||||
}
|
||||
Utils.initDefaultKeys()
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,11 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
|||
[[.title: "About Repository", .action: "segue", .link: "showAboutRepositorySegue"],],
|
||||
|
||||
// section 1
|
||||
[
|
||||
[.title: "Password Generator Flavor", .action: "none", .style: CellDataStyle.value1],
|
||||
],
|
||||
|
||||
// section 2
|
||||
[
|
||||
[.title: "Remember Passphrase", .action: "none",],
|
||||
],
|
||||
|
|
@ -81,7 +86,7 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
|||
cell.accessoryView = accessoryView
|
||||
cell.selectionStyle = .none
|
||||
hideUnknownSwitch.isOn = Defaults[.isHideUnknownOn]
|
||||
case "Hide One Time Password Fields":
|
||||
case "Hide OTP 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)
|
||||
|
|
@ -101,11 +106,53 @@ class GeneralSettingsTableViewController: BasicStaticTableViewController {
|
|||
cell.accessoryType = .none
|
||||
cell.selectionStyle = .none
|
||||
cell.accessoryView = showFolderSwitch
|
||||
case "Password Generator Flavor":
|
||||
cell.accessoryType = .disclosureIndicator
|
||||
cell.detailTextLabel?.text = Defaults[.passwordGeneratorFlavor]
|
||||
default: break
|
||||
}
|
||||
return cell
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
super.tableView(tableView, didSelectRowAt: indexPath)
|
||||
let cell = tableView.cellForRow(at: indexPath)!
|
||||
if cell.textLabel!.text! == "Password Generator Flavor" {
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
showPasswordGeneratorFlavorActionSheet(sourceCell: cell)
|
||||
}
|
||||
}
|
||||
|
||||
func showPasswordGeneratorFlavorActionSheet(sourceCell: UITableViewCell) {
|
||||
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
var randomFlavorActionTitle = ""
|
||||
var appleFlavorActionTitle = ""
|
||||
if Defaults[.passwordGeneratorFlavor] == "Random" {
|
||||
randomFlavorActionTitle = "✓ Random String"
|
||||
appleFlavorActionTitle = "Apple's Keychain Style"
|
||||
} else {
|
||||
randomFlavorActionTitle = "Random String"
|
||||
appleFlavorActionTitle = "✓ Apple's Keychain Style"
|
||||
}
|
||||
let randomFlavorAction = UIAlertAction(title: randomFlavorActionTitle, style: .default) { _ in
|
||||
Defaults[.passwordGeneratorFlavor] = "Random"
|
||||
sourceCell.detailTextLabel?.text = "Random"
|
||||
}
|
||||
|
||||
let appleFlavorAction = UIAlertAction(title: appleFlavorActionTitle, style: .default) { _ in
|
||||
Defaults[.passwordGeneratorFlavor] = "Apple"
|
||||
sourceCell.detailTextLabel?.text = "Apple"
|
||||
}
|
||||
|
||||
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
||||
optionMenu.addAction(randomFlavorAction)
|
||||
optionMenu.addAction(appleFlavorAction)
|
||||
optionMenu.addAction(cancelAction)
|
||||
optionMenu.popoverPresentationController?.sourceView = sourceCell
|
||||
optionMenu.popoverPresentationController?.sourceRect = sourceCell.bounds
|
||||
self.present(optionMenu, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
func tapHideUnknownSwitchDetailButton(_ sender: Any?) {
|
||||
let alertMessage = "Only \"key: value\" format in additional fields is supported. Unsupported fields will be given \"unkown\" keys. Turn on this switch to hide unsupported fields."
|
||||
let alertTitle = "Hide Unknown Fields"
|
||||
|
|
|
|||
|
|
@ -36,12 +36,7 @@ extension DefaultsKeys {
|
|||
static let isHideOTPOn = DefaultsKey<Bool>("isHideOTPOn")
|
||||
static let isRememberPassphraseOn = DefaultsKey<Bool>("isRememberPassphraseOn")
|
||||
static let isShowFolderOn = DefaultsKey<Bool>("isShowFolderOn")
|
||||
|
||||
static let passwordGenerationMethod = DefaultsKey<String>("passwordGenerationMethod")
|
||||
static let passwordGeneratorFlavor = DefaultsKey<String>("passwordGeneratorFlavor")
|
||||
|
||||
|
||||
func initDefaultKeys() {
|
||||
if Defaults[.passwordGenerationMethod] == "" {
|
||||
Defaults[.passwordGenerationMethod] = "Random"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,10 +38,10 @@ class Utils {
|
|||
}
|
||||
|
||||
static func generatePassword(length: Int) -> String{
|
||||
switch Defaults[.passwordGenerationMethod] {
|
||||
switch Defaults[.passwordGeneratorFlavor] {
|
||||
case "Random":
|
||||
return randomString(length: length)
|
||||
case "Keychain":
|
||||
case "Apple":
|
||||
return Keychain.generatePassword()
|
||||
default:
|
||||
return randomString(length: length)
|
||||
|
|
@ -138,6 +138,11 @@ class Utils {
|
|||
}
|
||||
return attributedPassword
|
||||
}
|
||||
static func initDefaultKeys() {
|
||||
if Defaults[.passwordGeneratorFlavor] == "" {
|
||||
Defaults[.passwordGeneratorFlavor] = "Random"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://gist.github.com/NikolaiRuhe/eeb135d20c84a7097516
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class FillPasswordTableViewCell: ContentTableViewCell {
|
|||
}
|
||||
|
||||
@IBAction func generatePassword(_ sender: UIButton) {
|
||||
let plainPassword = Utils.randomString(length: 16)
|
||||
let plainPassword = Utils.generatePassword(length: 16)
|
||||
contentTextField.attributedText = Utils.attributedPassword(plainPassword: plainPassword)
|
||||
Utils.copyToPasteboard(textToCopy: plainPassword)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue