Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. import UIKit
  2. import CoreData
  3.  
  4. class ViewResults: UIViewController {
  5.  
  6. //links username text field
  7. @IBOutlet weak var usernameTextField: UITextField!
  8. //links password text field
  9. @IBOutlet weak var passwordTextField: UITextField!
  10. //links "ok" button
  11. @IBOutlet weak var okBtn: UIButton!
  12.  
  13. override func viewDidLoad() {
  14. super.viewDidLoad()
  15. }
  16.  
  17. @IBAction func okButton(_ sender: Any) {
  18.  
  19. //user can only view results if the username = admin and password = hello
  20. if usernameTextField.text == "admin" && passwordTextField.text == "hello"
  21. {
  22. //alert pop up if login successful
  23. let alertController = UIAlertController(title: "Login Successful!", message:
  24. "Press Ok to view the results", preferredStyle: .alert)
  25. //takes user to results page if login is successful and user presses OK in alert
  26. alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in self.performSegue(withIdentifier: "results", sender: self) } ))
  27.  
  28.  
  29. self.present(alertController, animated: true, completion: nil)
  30. //debugging code outputs to console so I can check if login successful
  31. NSLog("Login successful")
  32. }
  33. else
  34. {
  35. //debugging code outputs to console so I can check if login failed
  36. NSLog("Login failed")
  37. //alert pop up if login fails
  38. let alertController = UIAlertController(title: "Incorrect Password!", message:
  39. "Please enter the correct password", preferredStyle: .alert)
  40. alertController.addAction(UIAlertAction(title: "Try Again", style: .default))
  41.  
  42. self.present(alertController, animated: true, completion: nil)
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement