mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-10 01:47:40 +01:00
Fix totp column size #2154
This commit is contained in:
parent
790b959054
commit
a1021f9dc3
@ -267,7 +267,10 @@ public class MySQL extends AbstractSqlDataSource {
|
||||
|
||||
if (isColumnMissing(md, col.TOTP_KEY)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.TOTP_KEY + " VARCHAR(16);");
|
||||
+ " ADD COLUMN " + col.TOTP_KEY + " VARCHAR(32);");
|
||||
} else if (isColumnSizeIncorrect(md, col.TOTP_KEY, 32)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ALTER COLUMN " + col.TOTP_KEY + " VARCHAR(32);");
|
||||
}
|
||||
|
||||
if (!col.PLAYER_UUID.isEmpty() && isColumnMissing(md, col.PLAYER_UUID)) {
|
||||
@ -284,6 +287,16 @@ public class MySQL extends AbstractSqlDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isColumnSizeIncorrect(DatabaseMetaData metaData, String columnName, int size) throws SQLException {
|
||||
try (ResultSet rs = metaData.getColumns(null, null, tableName, columnName)) {
|
||||
if (!rs.next()) {
|
||||
throw new RuntimeException("Column " + columnName + " doesn't exist!");
|
||||
}
|
||||
int currentSize = rs.getInt("COLUMN_SIZE");
|
||||
return size != currentSize;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerAuth getAuth(String user) {
|
||||
String sql = "SELECT * FROM " + tableName + " WHERE " + col.NAME + "=?;";
|
||||
|
@ -242,7 +242,10 @@ public class PostgreSqlDataSource extends AbstractSqlDataSource {
|
||||
|
||||
if (isColumnMissing(md, col.TOTP_KEY)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.TOTP_KEY + " VARCHAR(16);");
|
||||
+ " ADD COLUMN " + col.TOTP_KEY + " VARCHAR(32);");
|
||||
} else if (isColumnSizeIncorrect(md, col.TOTP_KEY, 32)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ALTER COLUMN " + col.TOTP_KEY + " VARCHAR(32);");
|
||||
}
|
||||
|
||||
if (!col.PLAYER_UUID.isEmpty() && isColumnMissing(md, col.PLAYER_UUID)) {
|
||||
@ -259,6 +262,16 @@ public class PostgreSqlDataSource extends AbstractSqlDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isColumnSizeIncorrect(DatabaseMetaData metaData, String columnName, int size) throws SQLException {
|
||||
try (ResultSet rs = metaData.getColumns(null, null, tableName, columnName)) {
|
||||
if (!rs.next()) {
|
||||
throw new RuntimeException("Column " + columnName + " doesn't exist!");
|
||||
}
|
||||
int currentSize = rs.getInt("COLUMN_SIZE");
|
||||
return size != currentSize;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerAuth getAuth(String user) {
|
||||
String sql = "SELECT * FROM " + tableName + " WHERE " + col.NAME + "=?;";
|
||||
|
@ -183,7 +183,10 @@ public class SQLite extends AbstractSqlDataSource {
|
||||
|
||||
if (isColumnMissing(md, col.TOTP_KEY)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ADD COLUMN " + col.TOTP_KEY + " VARCHAR(16);");
|
||||
+ " ADD COLUMN " + col.TOTP_KEY + " VARCHAR(32);");
|
||||
} else if (isColumnSizeIncorrect(md, col.TOTP_KEY, 32)) {
|
||||
st.executeUpdate("ALTER TABLE " + tableName
|
||||
+ " ALTER COLUMN " + col.TOTP_KEY + " VARCHAR(32);");
|
||||
}
|
||||
|
||||
if (!col.PLAYER_UUID.isEmpty() && isColumnMissing(md, col.PLAYER_UUID)) {
|
||||
@ -214,6 +217,16 @@ public class SQLite extends AbstractSqlDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isColumnSizeIncorrect(DatabaseMetaData metaData, String columnName, int size) throws SQLException {
|
||||
try (ResultSet rs = metaData.getColumns(null, null, tableName, columnName)) {
|
||||
if (!rs.next()) {
|
||||
throw new RuntimeException("Column " + columnName + " doesn't exist!");
|
||||
}
|
||||
int currentSize = rs.getInt("COLUMN_SIZE");
|
||||
return size != currentSize;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
close(con);
|
||||
|
Loading…
Reference in New Issue
Block a user