Move codes from utils to password and passwordstore
This commit is contained in:
parent
429ac1c915
commit
1ab70cf6d7
6 changed files with 41 additions and 40 deletions
|
|
@ -70,7 +70,7 @@ class AboutRepositoryTableViewController: BasicStaticTableViewController {
|
|||
[[.style: CellDataStyle.value1, .accessoryType: type, .title: "Passwords", .detailText: numberOfPasswordsString],
|
||||
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Size", .detailText: sizeOfRepositoryString],
|
||||
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Local Commits", .detailText: String(self?.passwordStore.numberOfLocalCommits() ?? 0)],
|
||||
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Last Synced", .detailText: Utils.getLastSyncedTimeString()],
|
||||
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Last Synced", .detailText: self?.passwordStore.getLastSyncedTimeString() ?? "Unknown"],
|
||||
[.style: CellDataStyle.value1, .accessoryType: type, .title: "Commits", .detailText: numberOfCommitsString],
|
||||
[.title: "Commit Logs", .action: "segue", .link: "showCommitLogsSegue"],
|
||||
],
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ class PasswordEditorTableViewController: UITableViewController, FillPasswordTabl
|
|||
showPasswordSettings()
|
||||
|
||||
let length = passwordLengthCell?.roundedValue ?? 0
|
||||
let plainPassword = Utils.generatePassword(length: length)
|
||||
let plainPassword = Password.generatePassword(length: length)
|
||||
SecurePasteboard.shared.copy(textToCopy: plainPassword)
|
||||
|
||||
// update tableData so to make sure reloadData() works correctly
|
||||
|
|
|
|||
|
|
@ -540,7 +540,7 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
|
|||
self.tableView.layer.removeAnimation(forKey: "UITableViewReloadDataAnimationKey")
|
||||
|
||||
// set the sync control title
|
||||
let atribbutedTitle = "Last Synced: \(Utils.getLastSyncedTimeString())"
|
||||
let atribbutedTitle = "Last Synced: \(passwordStore.getLastSyncedTimeString())"
|
||||
syncControl.attributedTitle = NSAttributedString(string: atribbutedTitle)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,43 +25,6 @@ public class Utils {
|
|||
removeFileIfExists(atPath: url.path)
|
||||
}
|
||||
|
||||
public static func getLastSyncedTimeString() -> String {
|
||||
guard let lastSyncedTime = SharedDefaults[.lastSyncedTime] else {
|
||||
return "Oops! Sync again?"
|
||||
}
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .medium
|
||||
formatter.timeStyle = .short
|
||||
return formatter.string(from: lastSyncedTime)
|
||||
}
|
||||
|
||||
public static func generatePassword(length: Int) -> String{
|
||||
switch SharedDefaults[.passwordGeneratorFlavor] {
|
||||
case "Random":
|
||||
return randomString(length: length)
|
||||
case "Apple":
|
||||
return Keychain.generatePassword()
|
||||
default:
|
||||
return randomString(length: length)
|
||||
}
|
||||
}
|
||||
|
||||
public static func randomString(length: Int) -> String {
|
||||
|
||||
let letters : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*_+-="
|
||||
let len = UInt32(letters.length)
|
||||
|
||||
var randomString = ""
|
||||
|
||||
for _ in 0 ..< length {
|
||||
let rand = arc4random_uniform(len)
|
||||
var nextChar = letters.character(at: Int(rand))
|
||||
randomString += NSString(characters: &nextChar, length: 1) as String
|
||||
}
|
||||
|
||||
return randomString
|
||||
}
|
||||
|
||||
public static func getPasswordFromKeychain(name: String) -> String? {
|
||||
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
||||
do {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import Foundation
|
|||
import SwiftyUserDefaults
|
||||
import OneTimePassword
|
||||
import Base32
|
||||
import KeychainAccess
|
||||
|
||||
public struct AdditionField: Equatable {
|
||||
public var title: String = ""
|
||||
|
|
@ -377,4 +378,31 @@ public class Password {
|
|||
let (key, _) = getKeyValuePair(from: line)
|
||||
return Password.OTP_KEYWORDS.contains(key ?? "")
|
||||
}
|
||||
|
||||
public static func generatePassword(length: Int) -> String{
|
||||
switch SharedDefaults[.passwordGeneratorFlavor] {
|
||||
case "Random":
|
||||
return randomString(length: length)
|
||||
case "Apple":
|
||||
return Keychain.generatePassword()
|
||||
default:
|
||||
return randomString(length: length)
|
||||
}
|
||||
}
|
||||
|
||||
private static func randomString(length: Int) -> String {
|
||||
|
||||
let letters : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*_+-="
|
||||
let len = UInt32(letters.length)
|
||||
|
||||
var randomString = ""
|
||||
|
||||
for _ in 0 ..< length {
|
||||
let rand = arc4random_uniform(len)
|
||||
var nextChar = letters.character(at: Int(rand))
|
||||
randomString += NSString(characters: &nextChar, length: 1) as String
|
||||
}
|
||||
|
||||
return randomString
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -912,4 +912,14 @@ public class PasswordStore {
|
|||
print(error)
|
||||
}
|
||||
}
|
||||
|
||||
public func getLastSyncedTimeString() -> String {
|
||||
guard let lastSyncedTime = SharedDefaults[.lastSyncedTime] else {
|
||||
return "Oops! Sync again?"
|
||||
}
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .medium
|
||||
formatter.timeStyle = .short
|
||||
return formatter.string(from: lastSyncedTime)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue