My app only has a password field in plain text. However, I need users to be able to open the app after the first time and not have to put in the password every time, only the first time. I don't want to use keychain because the password is not put in by the owner of the device but someone else. Here is my code for the password page, if that matters:
import UIKit
class LoginVC: UIViewController {
@IBOutlet weak var textpassword: UITextField!
@IBAction func btnActionLogin(_ sender: Any) {
UserDefaults.standard.set(true, forKey: "status")
if textpassword.text == "KEY" {
runbutton()
}
else {
alertController.addAction(okAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: nil)
}
}
// Create the alert controller
let alertController = UIAlertController(title: "Password", message: "Please contact Admin for access to the App", preferredStyle: .alert)
// Create the actions
let okAction = UIAlertAction(title: "OK", style: UIAlertAction.Style.default) {
UIAlertAction in
NSLog("OK Pressed")
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel) {
UIAlertAction in
NSLog("Cancel Pressed")
}
func runbutton() {
let tabBarViewController = UIStoryboard(name: Constants.Storyboard.mainStoryBoard, bundle: nil).instantiateViewController(withIdentifier: Constants.Storyboard.tabBarController) as! UITabBarController
view.window?.rootViewController = tabBarViewController
view.window?.makeKeyAndVisible()
}
func touchBegin(_ touches: Set<UITouch>, with event: UIEvent?) {
view.endEditing(true)
}
struct Constants {
struct Storyboard {
static let homeViewController = "loginvc"
static let tabBarController = "TabBarVC"
static let mainStoryBoard = "Main"
}
}
}