使用jsf和postgresql进行身份验证

时间:2014-04-09 15:37:38

标签: postgresql jsf

我尝试用jsf和postgres数据库进行身份验证。 我的班级conect.java

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean 
@SessionScoped
public class connect {
private  boolean connected;
 private  String pass;
  private   String user;
      private   String message;

public boolean isConnected() {
    return connected;
}

public void setConnected(boolean connected) {
    this.connected = connected;
}

public String getPass() {
    return pass;
}

public void setPass(String pass) {
    this.pass = pass;
}

public String getUser() {
    return user;
}

public void setUser(String user) {
    this.user = user;
}

public String getMessage() {
    return message;
  }

  public void setMessage(String message) {
      this.message = message;
  }


 public String check()
 {
   Connection c = null;
   Statement stmt = null;
   try {

     c = DriverManager
        .getConnection("jdbc:postgresql://localhost:5432/login", "postgres", "1234");
     c.setAutoCommit(false);
     System.out.println("Opened database successfully");

     stmt = c.createStatement();
     ResultSet rs = stmt.executeQuery( "SELECT * FROM users;" );
     while ( rs.next() ) {

       int iduser = rs.getInt("iduser");
         String  username = rs.getString("username");
        String password  = rs.getString("password");
         System.out.println( "ID = " + iduser );
      System.out.println( "USERNAME = " + username );
      System.out.println( "PASSWORD = " + password );



  if(user.equals(username) &&(pass.equals(password))){

   message="admin";
  }
 else message="error";

     }
     rs.close();
     stmt.close();
     c.close();
   } catch ( Exception e ) {
     System.err.println( e.getClass().getName()+": "+ e.getMessage() );

   }
   System.out.println("Operation done successfully");
   return message;
 }


public connect() {
}

public static void main( String args[] ){
connect c= new connect();
c.check();
}

}

该程序从数据库中恢复了良好的信息,问题是该程序只考虑了"用户"的最新用户名和密码。表。有人能告诉我问题出在哪里

0 个答案:

没有答案