Add revision args to account hash/salts

This commit is contained in:
Vortrex
2023-03-04 23:45:14 -06:00
parent eb7512f75c
commit 90caff03a6

View File

@@ -79,7 +79,7 @@ class AccountData {
this.databaseId = toInteger(dbAssoc["acct_id"]); this.databaseId = toInteger(dbAssoc["acct_id"]);
this.name = toString(dbAssoc["acct_name"]); this.name = toString(dbAssoc["acct_name"]);
this.password = toString(dbAssoc["acct_pass"]); this.password = toString(dbAssoc["acct_pass"]);
this.password = toString(dbAssoc["acct_pass_revision"]); this.passwordRevision = toString(dbAssoc["acct_pass_revision"]);
this.registerDate = toInteger(dbAssoc["acct_when_registered"]); this.registerDate = toInteger(dbAssoc["acct_when_registered"]);
this.flags = { this.flags = {
moderation: toInteger(dbAssoc["acct_svr_mod_flags"]), moderation: toInteger(dbAssoc["acct_svr_mod_flags"]),
@@ -815,9 +815,9 @@ function isNameRegistered(name) {
// =========================================================================== // ===========================================================================
function hashAccountPassword(name, password) { function hashAccountPassword(name, password, revision = 0) {
let hashFunction = getAccountHashingFunction(); let hashFunction = getAccountHashingFunction();
let saltedInfo = saltAccountInfo(name, password); let saltedInfo = saltAccountInfo(name, password, revision);
return hashFunction(saltedInfo); return hashFunction(saltedInfo);
} }
@@ -826,9 +826,9 @@ function hashAccountPassword(name, password) {
function saltAccountInfo(name, password, revision = 0) { function saltAccountInfo(name, password, revision = 0) {
let tempString = getSecurityConfig().accountPasswordSaltAlgorithm[revision]; let tempString = getSecurityConfig().accountPasswordSaltAlgorithm[revision];
tempString.replace("{NAME}", name); tempString = tempString.replace("{NAME}", name);
tempString.replace("{PASSWORD}", password); tempString = tempString.replace("{PASSWORD}", password);
tempString.replace("{SALTHASH}", getSecurityConfig().accountSaltHash[revision]) tempString = tempString.replace("{SALTHASH}", getSecurityConfig().accountSaltHash[revision]);
return tempString; return tempString;
} }
@@ -922,6 +922,7 @@ function saveAccountToDatabase(accountData) {
["acct_streaming_radio_volume", accountData.streamingRadioVolume], ["acct_streaming_radio_volume", accountData.streamingRadioVolume],
["acct_ip", accountData.ipAddress], ["acct_ip", accountData.ipAddress],
["acct_locale", accountData.locale], ["acct_locale", accountData.locale],
["acct_pass_revision", accountData.passwordRevision],
]; ];
let data2 = [ let data2 = [
@@ -1077,15 +1078,15 @@ function saveAccountContactsToDatabase(accountContactData) {
// =========================================================================== // ===========================================================================
function createAccount(name, password, email = "") { function createAccount(name, password, email = "", passwordRevision = 0) {
let dbConnection = connectToDatabase(); let dbConnection = connectToDatabase();
if (dbConnection) { if (dbConnection) {
let hashedPassword = hashAccountPassword(name, password); let hashedPassword = hashAccountPassword(name, password, passwordRevision);
let safeName = escapeDatabaseString(dbConnection, name); let safeName = escapeDatabaseString(dbConnection, name);
let safeEmail = escapeDatabaseString(dbConnection, email); let safeEmail = escapeDatabaseString(dbConnection, email);
let dbQuery = queryDatabase(dbConnection, `INSERT INTO acct_main (acct_name, acct_pass, acct_email, acct_when_registered) VALUES ('${safeName}', '${hashedPassword}', '${safeEmail}', UNIX_TIMESTAMP())`); let dbQuery = queryDatabase(dbConnection, `INSERT INTO acct_main (acct_name, acct_pass, acct_email, acct_when_registered, acct_pass_revision) VALUES ('${safeName}', '${hashedPassword}', '${safeEmail}', UNIX_TIMESTAMP(), ${passwordRevision})`);
if (getDatabaseInsertId(dbConnection) > 0) { if (getDatabaseInsertId(dbConnection) > 0) {
let insertId = getDatabaseInsertId(dbConnection); let insertId = getDatabaseInsertId(dbConnection);
createDefaultAccountServerData(insertId); createDefaultAccountServerData(insertId);
@@ -1485,6 +1486,8 @@ function savePlayerToDatabase(client) {
} }
} }
getPlayerCurrentSubAccount(client).payDayAmount = getPlayerData(client).payDayAmount;
saveSubAccountToDatabase(getPlayerCurrentSubAccount(client)); saveSubAccountToDatabase(getPlayerCurrentSubAccount(client));
} }
logToConsole(LOG_DEBUG, `[V.RP.Account]: Saved client ${getPlayerDisplayForConsole(client)} to database successfully!`); logToConsole(LOG_DEBUG, `[V.RP.Account]: Saved client ${getPlayerDisplayForConsole(client)} to database successfully!`);