0

I'm trying to make function to let someone change his/her password inside the program that i'm making. i'm trying to make a IF statement where i check if he put his old password right and then i check if he put his new password twice and if they are the same.

My problem is that when run the IF statement that it will turn False no matter what i input. even if its the right answer. i tried a few things to get around it but it doesn't work.

WachtwoordVeranderenController.java

package testswitch;

import java.net.URL;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;

/**
 *
 * @author Peltos
 */
public class WachtwoordVeranderenController implements Initializable {

@FXML TextField FXOudWachtwoord, FXNieuwWachtwoord, FXBevestigWachtwoord;
@FXML Button gevondenButton;

String id = MainController.getUsername();
String password = MainController.getPassword();

Database database = Main.getDatabase();



@FXML
private void writeToDB() throws SQLException {

    String query = "UPDATE testDatabase.Gevonden SET "
            + "Password=?, "
            + "WHERE Username=?;";

    PreparedStatement statement = database.prepareStatement(query);

    if ((FXNieuwWachtwoord.getText() == password) && (FXNieuwWachtwoord.getText() == FXBevestigWachtwoord.getText())) {
        try {
            System.out.println("gelukt!");
            statement.setString(1, FXNieuwWachtwoord.getText());
            statement.setString(2, id);
            //statement.executeUpdate();
            MainNavigator.loadVista(MainNavigator.START);
        } catch(SQLException ex) {
            ex.printStackTrace();
        }
    }
    else{
        System.out.println("Error");
        System.out.println("Password = " +password);
        System.out.println("FXOudWachtwoord = " +FXOudWachtwoord.getText());
        System.out.println("FXNieuwWachtwoord = " +FXNieuwWachtwoord.getText());
        System.out.println("FXBevestigWachtwoord = " +FXBevestigWachtwoord.getText());
    }
}

@FXML
private void cancel() {
    MainNavigator.loadVista(MainNavigator.START);
}

@Override
public void initialize(URL url, ResourceBundle rb) {
}

}

I don't have any errors in my output. It just always takes the ELSE statement no matter what i do. I feel like that the .getText() has something to do with it.

takendarkk
  • 3,347
  • 8
  • 25
  • 37
Ron Pelt
  • 25
  • 6

0 Answers0