?? login.java
字號:
/***************************************************
*
* 源文件名: Login.java
* 功 能: 夢想年華新聞系統 - 用戶登錄類
* 作者:夢想年華 [DreamTime]
* Email:fanwsp@126.com
* QQ:122142023
* CopyRight(c)2005-2006 by DreamTime
*
****************************************************
*/
package dreamtime.dreamnews; //指定類所在的包
import java.sql.*;
import dreamtime.dreamnews.Function;
import dreamtime.dreamnews.DBConnection;
import dreamtime.dreamnews.MD5;
public class Login
{
DBConnection DBConn = new DBConnection();
Function Fun = new Function();
MD5 md5 = new MD5();
public static int AdminID;
public static int AdminType;
public static int LoginNum;
public Login()
{
}
/*********************************************************
* 函數名:LoginCheck
* 作 用:驗證登錄
* 參 數:s1,s2,s3: 字符串型,登錄用戶名,密碼,IP
* 返回值:布爾型。登錄成功返回 Ture,否則返回 False
***********************************************************/
public boolean LoginCheck(String s1,String s2,String s3)
{
String [] sLog = new String[5];
try
{
Connection Conn = DBConn.getConn();
Statement stmt = Conn.createStatement(1004,1007);
ResultSet rs = null;
boolean OK = true;
String AdminPwd = "";
String User = Fun.CheckReplace(s1);
String Pwd = md5.getMD5ofStr(md5.getMD5ofStr(Fun.CheckReplace(s2)));
String Sql = "select * from Admin where AdminName='" + User + "'";
rs = stmt.executeQuery(Sql);
sLog[0] = User;
sLog[2] = (new java.util.Date()).toLocaleString();
sLog[3] = s3;
if (!rs.next())
{
sLog[1] = "用戶登錄 [ 用戶名不存在 ]";
sLog[4] = "No";
Fun.AddLog(sLog);
OK = false;
}
else
{
AdminPwd = rs.getString("AdminPwd");
if(Pwd.equals(AdminPwd))
{
AdminID=rs.getInt("AdminID");
AdminType=rs.getInt("AdminType");
LoginNum = rs.getInt("LoginNum");
sLog[1] = "用戶登錄";
sLog[4] = "Yes";
UpdateLogin(s3,sLog[2],LoginNum+1,AdminID);
Fun.AddLog(sLog);
OK = true;
}
else
{
sLog[1] = "用戶登錄[密碼錯誤]";
sLog[4] = "No";
Fun.AddLog(sLog);
OK = false;
}
}
return OK;
}
catch(SQLException e)
{
//e.printStackTrace();
//return e.getMessage().toString();
sLog[1] = "用戶登錄[程序異常]";
sLog[4] = "No";
Fun.AddLog(sLog);
return false;
}
}
/*********************************************************
* 函數名:UpdateLogin
* 作 用:更新登錄信息
* 參 數:s1,最后登錄的IP地址
* s2,最后登錄的時間
* iNum,登錄資料
* ID,管理員ID
* 返回值:布爾型。更新成功返回 Ture,否則返回 False
***********************************************************/
public boolean UpdateLogin(String s1,String s2,int iNum,int ID)
{
String sql = "";
try
{
Connection Conn = DBConn.getConn();
Statement stmt = Conn.createStatement(1004,1007);
ResultSet rs = null;
sql = "update Admin set ";
sql += "LastLoginIP='" + s1 + "',";
sql += "LastLoginTime='" + s2 + "',";
sql += "LoginNum=" + iNum + " where AdminID=" + ID ;
stmt.executeUpdate(sql);
stmt.close();
Conn.close();
return true;
}catch(SQLException e)
{
//e.printStackTrace();
System.out.print(sql);
return false;
}
}
//測試
public static void main(String[] args)
{
Login login = new Login();
if (login.LoginCheck("dream","dream","172.16.166.50"))
System.out.println("Success!" + login.AdminID);
else
System.out.println("Fail");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -