package zhxt.login.ejb;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.ejb.*;
/*************************************************
Copyright (C), 2002-2004, 易新科技有限公司
File name: LoginBean.java
Author:zcl Version:0.1 Date: 2004.3.13
Description: 完成用户版本和用户登录的实体Bean(BMP),使用了LoginDAO,主要实现对用户的认证功能
Others:
Function List:
1.
2.
History:
1. Date:
Author:
Modification:
*************************************************/
public class LoginBean implements javax.ejb.EntityBean {
private javax.ejb.EntityContext myEntityCtx;
private String username; /*用户帐号*/
private String password;/*用户密码*/
private String paw;
private LoginDAO DAO = new LoginDAO();/*数据库访问DAO成员变量*/
/**
* ejbActivate
*/
public void ejbActivate() {
}
/**
* ejbLoad
*/
public void ejbLoad() {
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
}
/**
* ejbRemove
*/
public void ejbRemove() throws javax.ejb.RemoveException {
}
/**
* ejbStore
*/
public void ejbStore() {
}
/**
* getEntityContext
*/
public javax.ejb.EntityContext getEntityContext() {
return myEntityCtx;
}
/**
* setEntityContext
*/
public void setEntityContext(javax.ejb.EntityContext ctx) {
myEntityCtx = ctx;
}
/**
* unsetEntityContext
*/
public void unsetEntityContext() {
myEntityCtx = null;
}
/**
* ejbCreate
*/
public zhxt.login.ejb.LoginKey ejbCreate()
throws javax.ejb.CreateException {
return null;
}
/**
* ejbPostCreate
*/
public void ejbPostCreate() throws javax.ejb.CreateException {
}
/**
* ejbFindByPrimaryKey
*/
public zhxt.login.ejb.LoginKey ejbFindByPrimaryKey(
zhxt.login.ejb.LoginKey primaryKey)
throws javax.ejb.FinderException {
return null;
}
/**
* 带用户帐号和密码的构造函数实现.
* username:用户帐号;password:用户密码
*/
public LoginKey ejbCreate(String username,String password)
throws javax.ejb.CreateException
{
this.paw = password;
this.username = username;
return new LoginKey("",false);
}
public void ejbPostCreate(String username,String password)
throws javax.ejb.CreateException{
};
/**
* 根据用户编码返回一个主要对象
*/
public LoginKey ejbFindByUsername(String username) throws FinderException
{
return new LoginKey(username,false);
}
/**
*判断用户认证函数。
*主要实现对用户帐号和密码的认证
* 返回值:为布尔变量。true:认证成功;false:认证失败。
*/
public boolean isPass(String uname,String passwd)
{
Connection conn=null;
try
{
Class.forName ("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.166:1521:ORCL","zhxt","zhxt");
DAO.setConn( conn);
password = DAO.getPassByAccount(uname);
System.out.println(password+" " +passwd);
if (password.equals(passwd))
{
conn.close();
return true;
}
else
{
conn.close();
return false;
}
}
catch(Exception e)
{
throw new EJBException("ejbCreate:(errir80888)" + e.toString());
}
};
/**
* Returns the password.
* @return String
*/
public String getPassword() {
return password;
}
/**
* Returns the username.
* @return String
*/
public String getUsername() {
return username;
}
/**
* Sets the password.
* @param password The password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* Sets the username.
* @param username The username to set
*/
public void setUsername(String username) {
this.username = username;
}
}