java中的验证错误登录寄存器



我正在尝试设置确认密码的验证,所有文本字段都必须有值。我只是一个初学者,先生,我正在练习建立登录和注册程序。

对不起,我英语说得不太好。

我的问题是我的代码没有运行FINE。它不断告诉"填满空间"

String username = usernamefield.getText();
String password = passwordfield.getText();
String cpassword = cpasswordfield.getText();
if ((username != null) || (password != null) || (cpassword != null)) {
    if (password == cpassword) {
        db.insertData(username, password);
        JOptionPane.showMessageDialog(null, "data has been entered");
    }
    else {
        JOptionPane.showMessageDialog(null, "Please Fill the spaces");
    }
}
else if (password != cpassword) {
    JOptionPane.showMessageDialog(null, "Password Mismatch");
}
if((username != null) || (password != null) || (cpassword != null) ){
if(password.equals(cpassword)){
    db.insertData(username, password);
    JOptionPane.showMessageDialog(null, "data has been entered");
}else {
    JOptionPane.showMessageDialog(null, "Password Mismatch");
}

 } else {
JOptionPane.showMessageDialog(null, "Please Fill the spaces");
}

试试这个代码。您应该使用equals()而不是==进行字符串比较

最新更新