AuthMe 3.0
//Changes 3.0:// * Repackaging from uk.org.whoami.authme to fr.xephi.authme, please developpers, update! * Rewrite some of parts of the plugin * Some code was already perfect , also did not change it :p * Full support for phpbb3 * Add full support for WordPress + passwordHash: WORDPRESS * Completely rewrite Management system for inventories and tp issues, Thanks to : [[http://dev.bukkit.org/profiles/Possible/|Possible]] * Rework on /passpartu command * Completely rewrite the password encryption method * Add a way for developers to add their own Password Encryption Method on AuthMe via event way (please see fr.xephi.authme.events.PasswordEncryptionEvent) * Add an auto purge with players.dat removing method and essentials files removing ( if you want authme to hook with an another plugin let me know ) * Complete Hook with BungeeCord by removing the /server command before login * message_lang.yml will never be overwritten with English Strings , but correctly update the message_lang.yml when needed to * Fix a lot of issues mentioned in tickets , commants , or by mp, Thanks for all your reports!
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class FlatToSql {
|
||||
|
||||
private static String tableName;
|
||||
private static String columnName;
|
||||
private static String columnPassword;
|
||||
private static String columnIp;
|
||||
private static String columnLastLogin;
|
||||
private static String lastlocX;
|
||||
private static String lastlocY;
|
||||
private static String lastlocZ;
|
||||
private static String lastlocWorld;
|
||||
private static String columnEmail;
|
||||
private static File source;
|
||||
private static File output;
|
||||
|
||||
public static void FlatToSqlConverter() throws IOException {
|
||||
tableName = Settings.getMySQLTablename;
|
||||
columnName = Settings.getMySQLColumnName;
|
||||
columnPassword = Settings.getMySQLColumnPassword;
|
||||
columnIp = Settings.getMySQLColumnIp;
|
||||
columnLastLogin = Settings.getMySQLColumnLastLogin;
|
||||
lastlocX = Settings.getMySQLlastlocX;
|
||||
lastlocY = Settings.getMySQLlastlocY;
|
||||
lastlocZ = Settings.getMySQLlastlocZ;
|
||||
lastlocWorld = Settings.getMySQLlastlocWorld;
|
||||
columnEmail = Settings.getMySQLColumnEmail;
|
||||
|
||||
try {
|
||||
source = new File(AuthMe.getInstance().getDataFolder() + File.separator + "auths.db");
|
||||
source.createNewFile();
|
||||
output = new File(AuthMe.getInstance().getDataFolder() + File.separator + "authme.sql");
|
||||
BufferedReader br = null;
|
||||
BufferedWriter sql = null;
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
sql = new BufferedWriter(new FileWriter(output));
|
||||
String createDB = " CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
||||
+ "id INTEGER AUTO_INCREMENT,"
|
||||
+ columnName + " VARCHAR(255) NOT NULL UNIQUE,"
|
||||
+ columnPassword + " VARCHAR(255) NOT NULL,"
|
||||
+ columnIp + " VARCHAR(40) NOT NULL,"
|
||||
+ columnLastLogin + " BIGINT,"
|
||||
+ lastlocX + " smallint(6) DEFAULT '0',"
|
||||
+ lastlocY + " smallint(6) DEFAULT '0',"
|
||||
+ lastlocZ + " smallint(6) DEFAULT '0',"
|
||||
+ lastlocWorld + " VARCHAR(255) DEFAULT 'world',"
|
||||
+ columnEmail + " VARCHAR(255) NOT NULL,"
|
||||
+ "CONSTRAINT table_const_prim PRIMARY KEY (id));";
|
||||
sql.write(createDB);
|
||||
String line;
|
||||
int i = 1;
|
||||
String newline;
|
||||
while ((line = br.readLine()) != null) {
|
||||
sql.newLine();
|
||||
String[] args = line.split(":");
|
||||
if (args.length == 4)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", 0, 0, 0, 'world', 'your@email.com');";
|
||||
else if (args.length == 7)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", 'world', 'your@email.com');";
|
||||
else if (args.length == 8)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', 'your@email.com');";
|
||||
else
|
||||
newline = "";
|
||||
if (newline != "")
|
||||
sql.write(newline);
|
||||
i = i + 1;
|
||||
}
|
||||
sql.close();
|
||||
br.close();
|
||||
ConsoleLogger.info("The FlatFile has been converted to authme.sql file");
|
||||
} catch (FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
|
||||
public class FlatToSqlite {
|
||||
|
||||
private static String tableName;
|
||||
private static String columnName;
|
||||
private static String columnPassword;
|
||||
private static String columnIp;
|
||||
private static String columnLastLogin;
|
||||
private static String lastlocX;
|
||||
private static String lastlocY;
|
||||
private static String lastlocZ;
|
||||
private static String lastlocWorld;
|
||||
private static String columnEmail;
|
||||
private static File source;
|
||||
private static String database;
|
||||
private static String columnID;
|
||||
private static Connection con;
|
||||
|
||||
public static String convert() throws IOException {
|
||||
database = Settings.getMySQLDatabase;
|
||||
tableName = Settings.getMySQLTablename;
|
||||
columnName = Settings.getMySQLColumnName;
|
||||
columnPassword = Settings.getMySQLColumnPassword;
|
||||
columnIp = Settings.getMySQLColumnIp;
|
||||
columnLastLogin = Settings.getMySQLColumnLastLogin;
|
||||
lastlocX = Settings.getMySQLlastlocX;
|
||||
lastlocY = Settings.getMySQLlastlocY;
|
||||
lastlocZ = Settings.getMySQLlastlocZ;
|
||||
lastlocWorld = Settings.getMySQLlastlocWorld;
|
||||
columnEmail = Settings.getMySQLColumnEmail;
|
||||
columnID = Settings.getMySQLColumnId;
|
||||
ConsoleLogger.info("Converting FlatFile to SQLite ...");
|
||||
if (new File(AuthMe.getInstance().getDataFolder() + File.separator + database + ".db").exists()) {
|
||||
return "The Database " + database + ".db can't be created cause the file already exist";
|
||||
}
|
||||
try {
|
||||
connect();
|
||||
setup();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.showError("Problem while trying to convert to sqlite !");
|
||||
return "Problem while trying to convert to sqlite !";
|
||||
}
|
||||
try {
|
||||
source = new File(AuthMe.getInstance().getDataFolder() + File.separator + "auths.db");
|
||||
source.createNewFile();
|
||||
BufferedReader br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
int i = 1;
|
||||
String newline;
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] args = line.split(":");
|
||||
if (args.length == 4)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", 0, 0, 0, 'world', 'your@email.com');";
|
||||
else if (args.length == 7)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", 'world', 'your@email.com');";
|
||||
else if (args.length == 8)
|
||||
newline = "INSERT INTO " + tableName + " VALUES (" + i + ", '" + args[0] + "', '" + args[1] + "', '" + args[2] + "', " + args[3] + ", " + args[4] + ", " + args[5] + ", " + args[6] + ", '" + args[7] + "', 'your@email.com');";
|
||||
else
|
||||
newline = "";
|
||||
if (newline != "")
|
||||
saveAuth(newline);
|
||||
i = i + 1;
|
||||
}
|
||||
br.close();
|
||||
ConsoleLogger.info("The FlatFile has been converted to " + database + ".db file");
|
||||
close();
|
||||
return ("The FlatFile has been converted to " + database + ".db file");
|
||||
} catch (FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
return "Errors appears while trying to convert to SQLite";
|
||||
}
|
||||
|
||||
private synchronized static void connect() throws ClassNotFoundException, SQLException {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
ConsoleLogger.info("SQLite driver loaded");
|
||||
con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/"+database+".db");
|
||||
}
|
||||
|
||||
private synchronized static void setup() throws SQLException {
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
st = con.createStatement();
|
||||
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
||||
+ columnID + " INTEGER AUTO_INCREMENT,"
|
||||
+ columnName + " VARCHAR(255) NOT NULL UNIQUE,"
|
||||
+ columnPassword + " VARCHAR(255) NOT NULL,"
|
||||
+ columnIp + " VARCHAR(40) NOT NULL,"
|
||||
+ columnLastLogin + " BIGINT,"
|
||||
+ lastlocX + " smallint(6) DEFAULT '0',"
|
||||
+ lastlocY + " smallint(6) DEFAULT '0',"
|
||||
+ lastlocZ + " smallint(6) DEFAULT '0',"
|
||||
+ lastlocWorld + " VARCHAR(255) DEFAULT 'world',"
|
||||
+ columnEmail + " VARCHAR(255) DEFAULT 'your@email.com',"
|
||||
+ "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));");
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ columnPassword + " VARCHAR(255) NOT NULL;");
|
||||
}
|
||||
rs.close();
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, columnIp);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ columnIp + " VARCHAR(40) NOT NULL;");
|
||||
}
|
||||
rs.close();
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN "
|
||||
+ columnLastLogin + " BIGINT;");
|
||||
}
|
||||
rs.close();
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, lastlocX);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocX + " smallint(6) NOT NULL DEFAULT '0'; "
|
||||
+ "ALTER TABLE " + tableName + " ADD COLUMN " + lastlocY + " smallint(6) NOT NULL DEFAULT '0'; "
|
||||
+ "ALTER TABLE " + tableName + " ADD COLUMN " + lastlocZ + " smallint(6) NOT NULL DEFAULT '0';");
|
||||
}
|
||||
rs.close();
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + lastlocZ + ";");
|
||||
}
|
||||
rs.close();
|
||||
rs = con.getMetaData().getColumns(null, null, tableName, columnEmail);
|
||||
if (!rs.next()) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';");
|
||||
}
|
||||
} finally {
|
||||
close(rs);
|
||||
close(st);
|
||||
}
|
||||
ConsoleLogger.info("SQLite Setup finished");
|
||||
}
|
||||
|
||||
private static synchronized boolean saveAuth(String s) {
|
||||
PreparedStatement pst = null;
|
||||
try {
|
||||
pst = con.prepareStatement(s);
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
close(pst);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void close(Statement st) {
|
||||
if (st != null) {
|
||||
try {
|
||||
st.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void close(ResultSet rs) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized static void close() {
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class RakamakConverter {
|
||||
|
||||
public AuthMe instance;
|
||||
|
||||
public RakamakConverter (AuthMe instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public RakamakConverter getInstance() {
|
||||
return this;
|
||||
}
|
||||
|
||||
private static HashAlgorithm hash;
|
||||
private static Boolean useIP;
|
||||
private static String fileName;
|
||||
private static String ipFileName;
|
||||
private static File source;
|
||||
private static File output;
|
||||
private static File ipfiles;
|
||||
private static boolean alreadyExist = false;
|
||||
|
||||
public static void RakamakConvert() throws IOException {
|
||||
hash = Settings.rakamakHash;
|
||||
useIP = Settings.rakamakUseIp;
|
||||
fileName = Settings.rakamakUsers;
|
||||
ipFileName = Settings.rakamakUsersIp;
|
||||
HashMap<String, String> playerIP = new HashMap<String, String>();
|
||||
HashMap<String, String> playerPSW = new HashMap<String, String>();
|
||||
try {
|
||||
source = new File(AuthMe.getInstance().getDataFolder() + File.separator + fileName);
|
||||
ipfiles = new File(AuthMe.getInstance().getDataFolder() + File.separator + ipFileName);
|
||||
output = new File(AuthMe.getInstance().getDataFolder() + File.separator + "auths.db");
|
||||
source.createNewFile();
|
||||
ipfiles.createNewFile();
|
||||
if (new File(AuthMe.getInstance().getDataFolder() + File.separator + "auths.db").exists()) {
|
||||
alreadyExist = true;
|
||||
}
|
||||
output.createNewFile();
|
||||
BufferedReader users = null;
|
||||
BufferedWriter outputDB = null;
|
||||
BufferedReader ipFile = null;
|
||||
ipFile = new BufferedReader(new FileReader(ipfiles));
|
||||
String line;
|
||||
String newLine = null;
|
||||
if (useIP) {
|
||||
String tempLine;
|
||||
while ((tempLine = ipFile.readLine()) != null) {
|
||||
if (tempLine.contains("=")) {
|
||||
String[] args = tempLine.split("=");
|
||||
playerIP.put(args[0], args[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
ipFile.close();
|
||||
users = new BufferedReader(new FileReader(source));
|
||||
while ((line = users.readLine()) != null) {
|
||||
if (line.contains("=")) {
|
||||
String[] arguments = line.split("=");
|
||||
try {
|
||||
playerPSW.put(arguments[0],PasswordSecurity.getHash(hash, arguments[1], arguments[0].toLowerCase()));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
users.close();
|
||||
outputDB = new BufferedWriter(new FileWriter(output));
|
||||
for (Entry<String, String> m : playerPSW.entrySet()) {
|
||||
if (useIP) {
|
||||
String player = m.getKey();
|
||||
String psw = playerPSW.get(player);
|
||||
String ip = playerIP.get(player);
|
||||
newLine = player + ":" + psw + ":" + ip + ":1325376060:0:0:0";
|
||||
} else {
|
||||
String player = m.getKey();
|
||||
String psw = playerPSW.get(player);
|
||||
String ip = "127.0.0.1";
|
||||
newLine = player + ":" + psw + ":" + ip + ":1325376060:0:0:0";
|
||||
}
|
||||
if (alreadyExist) outputDB.newLine();
|
||||
outputDB.write(newLine);
|
||||
System.out.println("Write line");
|
||||
outputDB.newLine();
|
||||
}
|
||||
outputDB.close();
|
||||
ConsoleLogger.info("Rakamak database has been converted to auths.db");
|
||||
} catch (FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package fr.xephi.authme.converter;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.cypherx.xauth.xAuth;
|
||||
import com.cypherx.xauth.database.Table;
|
||||
import com.cypherx.xauth.utils.xAuthLog;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class xAuthToFlat {
|
||||
|
||||
public AuthMe instance;
|
||||
public DataSource database;
|
||||
|
||||
public xAuthToFlat(AuthMe instance, DataSource database) {
|
||||
this.instance = instance;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public boolean convert(CommandSender sender) {
|
||||
if (instance.getServer().getPluginManager().getPlugin("xAuth") == null) {
|
||||
sender.sendMessage("[AuthMe] xAuth plugin not found");
|
||||
return false;
|
||||
}
|
||||
if (!(new File("./plugins/xAuth/xAuth.h2.db").exists())) {
|
||||
sender.sendMessage("[AuthMe] xAuth H2 database not found, checking for MySQL or SQLite data...");
|
||||
}
|
||||
List<Integer> players = getXAuthPlayers();
|
||||
if (players == null || players.isEmpty()) {
|
||||
sender.sendMessage("[AuthMe] Error while import xAuthPlayers");
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage("[AuthMe] Starting import...");
|
||||
for (int id : players) {
|
||||
String pl = getIdPlayer(id);
|
||||
String psw = getPassword(id);
|
||||
if (psw != null && !psw.isEmpty() && pl != null) {
|
||||
PlayerAuth auth = new PlayerAuth(pl, psw, "198.18.0.1", 0);
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
}
|
||||
sender.sendMessage("[AuthMe] Import done!");
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getIdPlayer(int id) {
|
||||
String realPass = "";
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = String.format("SELECT `playername` FROM `%s` WHERE `id` = ?",
|
||||
xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
|
||||
ps = conn.prepareStatement(sql);
|
||||
ps.setInt(1, id);
|
||||
rs = ps.executeQuery();
|
||||
if (!rs.next())
|
||||
return null;
|
||||
realPass = rs.getString("playername").toLowerCase();
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Failed to retrieve name for account: " + id, e);
|
||||
return null;
|
||||
} finally {
|
||||
xAuth.getPlugin().getDatabaseController().close(conn, ps, rs);
|
||||
}
|
||||
return realPass;
|
||||
}
|
||||
|
||||
public List<Integer> getXAuthPlayers() {
|
||||
List<Integer> xP = new ArrayList<Integer>();
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = String.format("SELECT * FROM `%s`",
|
||||
xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
|
||||
ps = conn.prepareStatement(sql);
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()) {
|
||||
xP.add(rs.getInt("id"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Cannot import xAuthPlayers", e);
|
||||
return new ArrayList<Integer>();
|
||||
} finally {
|
||||
xAuth.getPlugin().getDatabaseController().close(conn, ps, rs);
|
||||
}
|
||||
return xP;
|
||||
}
|
||||
|
||||
public String getPassword(int accountId) {
|
||||
String realPass = "";
|
||||
Connection conn = xAuth.getPlugin().getDatabaseController().getConnection();
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = String.format("SELECT `password`, `pwtype` FROM `%s` WHERE `id` = ?",
|
||||
xAuth.getPlugin().getDatabaseController().getTable(Table.ACCOUNT));
|
||||
ps = conn.prepareStatement(sql);
|
||||
ps.setInt(1, accountId);
|
||||
rs = ps.executeQuery();
|
||||
if (!rs.next())
|
||||
return null;
|
||||
realPass = rs.getString("password");
|
||||
} catch (SQLException e) {
|
||||
xAuthLog.severe("Failed to retrieve password hash for account: " + accountId, e);
|
||||
return null;
|
||||
} finally {
|
||||
xAuth.getPlugin().getDatabaseController().close(conn, ps, rs);
|
||||
}
|
||||
return realPass;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user