SHARE
TWEET

Untitled

a guest Dec 8th, 2019 120 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @IBOutlet weak var usernameField: UITextField!
  2.     @IBOutlet weak var passwordField: UITextField!
  3.    
  4.    
  5.     @IBOutlet weak var usernameErrorMessage: UILabel!
  6.     @IBOutlet weak var passwordErrorMessage: UILabel!
  7.    
  8.    
  9.     @IBOutlet weak var loginMessage: UILabel!
  10.    
  11.     @IBAction func loginPressed(_ sender: Any) {
  12.         var username = usernameField.text ?? ""
  13.         var password = passwordField.text ?? ""
  14.        
  15.         var validUsername = true
  16.         var validPassword = true
  17.        
  18.         loginMessage.isHidden = true
  19.        
  20.        
  21.         if username.characters.count < 4 {
  22.             if username.isEmpty {
  23.                 usernameErrorMessage.text = "Username cannot be empty"
  24.             } else {
  25.                 usernameErrorMessage.text = "Username too short"
  26.             }
  27.            
  28.            
  29.             usernameErrorMessage.isHidden = false
  30.             validUsername = false
  31.         } else {
  32.             usernameErrorMessage.isHidden = true
  33.         }
  34.        
  35.         if password.characters.count < 7 {
  36.             if password.isEmpty {
  37.                 passwordErrorMessage.text = "Password cannot be empty"
  38.             } else {
  39.                 passwordErrorMessage.text = "Password too short"
  40.             }
  41.            
  42.            
  43.             passwordErrorMessage.isHidden = false
  44.             validPassword = false
  45.         } else {
  46.             passwordErrorMessage.isHidden = true
  47.         }
  48.        
  49.         if validUsername && validPassword {
  50.            
  51.             if (username == "admin" && password == "password") {
  52.                 loginMessage.text = "Login success!"
  53.                 loginMessage.textColor = UIColor.green
  54.             } else {
  55.                 loginMessage.text = "Invalid username or password!"
  56.                 loginMessage.textColor = UIColor.red
  57.             }
  58.            
  59.            
  60.             loginMessage.isHidden = false
  61.         }
  62.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top