我正在开发一个软件,我有一个框架来保存用户。我有密码字段可以从保存新用户框架中获取密码。我选择二进制数据类型来保存密码。保存记录后,我从工作台查看它,密码字段有“BLOB”。我试过登录框架。但它不起作用。我没有使用任何加密方法。
我的查询如下和代码。我也想知道保存密码的最佳方法是什么。
//get password from password field in save user frame
String password = txtUserPassword.getPassword().toString();
/////////////////////////////////QUERY TO SAVE NEW USER////////////////////////////////////////////////////
//query to save the new user
"INSERT INTO user(username,fname,lname,password,contact,type,isDeleted) VALUES( '"+userName+"','"+fname+"','"+lname+"','"+password+"','"+contact+"','"+type+"','false' )"
///////////////////LOG IN FORM CODE/////////////////////////////////////////////////////////////////////
//in Login form ,get the user name and password and check with database value
String username = txtUsername.getText();
String password = new String(txtPassword.getPassword());
//take the values to result set
ResultSet rst = DB_Access.getData("SELECT username,password FROM user WHERE BINARY username='"+username+"' AND BINARY password = '"+password+"' ");
// check user existing or not in the if condition
if(rst.next())
{
Guesrname = txtUsername.getText(); // this user name to pass the user name to next form
this.dispose();
Seller sellFrame = new Seller(Guesrname ); // next appearing form
sellFrame.setVisible(true);
}
else
{
JOptionPane.showMessageDialog(this, "Invalid user name or password");
}