48 lines
1.6 KiB
Java
48 lines
1.6 KiB
Java
package cn.citycraft.CTZServer;
|
|
|
|
import cn.citycraft.PluginHelper.sql.KeyValue;
|
|
import cn.citycraft.PluginHelper.sql.SQLHelper;
|
|
import cn.citycraft.PluginHelper.utils.StringUtil;
|
|
|
|
public class CTZAuth {
|
|
static final String TableName = "ctzserver";
|
|
static final String UserField = "player";
|
|
static final String PWDField = "password";
|
|
static final String ISLoginField = "islogin";
|
|
static final String ALLOWLoginField = "allowlogin";
|
|
static SQLHelper sql;
|
|
|
|
public static void changePassword(String username, String password) {
|
|
// TODO 处理玩家密码修改事件
|
|
}
|
|
|
|
public static boolean checkPassword(String username, String password) {
|
|
return sql.isFieldExists(TableName, new KeyValue(UserField, username).add(PWDField, StringUtil.getMD5Code(password)));
|
|
}
|
|
|
|
public static void init(SQLHelper sql) {
|
|
CTZAuth.sql = sql;
|
|
}
|
|
|
|
public static boolean isLogin(String username) {
|
|
String result = sql.dbSelectFirst(TableName, ISLoginField, new KeyValue(UserField, username));
|
|
return (result != null && result.equalsIgnoreCase("1"));
|
|
}
|
|
|
|
public static boolean isRegistered(String username) {
|
|
return sql.isFieldExists(TableName, new KeyValue(UserField, username));
|
|
}
|
|
|
|
public static boolean login(String username) {
|
|
return sql.dbUpdate(TableName, new KeyValue(ALLOWLoginField, "1"), new KeyValue(UserField, username));
|
|
}
|
|
|
|
public static boolean registerPlayer(String username, String password) {
|
|
if (isRegistered(username))
|
|
return false;
|
|
else
|
|
return sql.dbInsert(TableName, new KeyValue(UserField, username).add(PWDField, StringUtil.getMD5Code(password)));
|
|
}
|
|
|
|
}
|