I am working on an app using LDAP authentication. I have been working on some code I found that allows me to use my existing PHP script. Everything appears to be working. I am getting the proper responses when I enter my network credentials - whether it is a good login or bad one. Right now, I'm just asking it to print "Access Granted" or "Access Denied". However, any attempts to do more - like a pop up window or a segue to a new View Controller crashes the app on the simulator.
Here is my code:
https://youtu.be/SIULwyOpxW8
func DoLogin(_ user:String, _ psw:String) {
let url = URL(string: "http://myserver.com/user/check_login_app.php")
let session = URLSession.shared
let request = NSMutableURLRequest(url: url!)
request.httpMethod = "POST"
let postString = "username=\(txtUsername.text!)&password=\(txtPassword.text!)"
request.httpBody = postString.data(using: String.Encoding.utf8)
let task = session.dataTask(with: request as URLRequest) {
data, response, error in
if error != nil {
return
}
let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
if(responseString == "1") {
self.goodLogin()
} else if (responseString == "0") {
self.badLogin()
}
}
task.resume()
txteNumber.text = ""
txtPassword.text = ""
}
func goodLogin() {
print("Access Granted!")
performSegue(withIdentifier: "loggedIn", sender: self)
}
func badLogin() {
print("Access denied!")
}As I stated previously, the app crashes as soon as I add Line #41 to my code.
I am not finding much luck with any searches, so I'm hoping someone can point out what I'm doing wrong. https://youtu.be/zUj04J3KxqI