vendredi 6 novembre 2015

Trying to create a log-in action in swift using sqlite

I'm new to swift and sqlite and am trying to create a user log-in action by calling elements from my database. I'm able to update my database but I'm having trouble checking if the user password matches with the password saved to the database. I want to check to see if the password matches, then switch to the home page of my application

This is what I have currently:

    @IBAction func loginTapped(sender: UIButton) {
    let usersDB = FMDatabase(path: databasePath as String)

    if usersDB.open() {
        let querySQL = "SELECT username FROM USERS WHERE password = '\(txtPassword.text)'"

        let results:FMResultSet? = usersDB.executeQuery(querySQL,
            withArgumentsInArray: nil)

        if results?.next() == true {
            status.text = "Logging in"
        } else {
            status.text = "Incorrect username or password"
            txtUsername.text = ""
            txtPassword.text = ""
        }
        usersDB.close()
    } else {
        print("Error: \(usersDB.lastErrorMessage())")
    }
}

Aucun commentaire:

Enregistrer un commentaire