如何将 jpasswordfield.getpassword() 登录框架与保存在 mysql 列中的安全 jpasswordfield 进行比较?我的数据库中存储了用户 ID 和密码,我想将输入的密码与存储在数据库中的密码进行比较。存储在数据库中的密码应该加密,这样管理员就看不到正确的密码。我会在你想的任何地方搜索,如果你知道我的问题,请帮助我,tnx
我的代码:
public class LoginTester {
public static String[] Passwords; // i try with char[], Array[], ... but not worked
private static Connection con;
private static Statement st;
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://%s:%s/%s?user=%s&password=%s";
url = String.format(url, "localhost", 3308, "logindb", "root", "root");
con = DriverManager.getConnection(url);
st = con.createStatement();
ResultSet rs = st.executeQuery("select * from users where username='" + TfUserName.getText() + "'");
rs.last();
int RowCount = rs.getRow();
rs.beforeFirst();
Passwords = new String[RowCount];
int i = 0;
while (rs.next()) {
Passwords[i] = rs.getString("password");
i++;
}
rs.close();
st.close();
con.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}