This commit is contained in:
Holly Stubbs 2021-09-25 16:35:01 +01:00
parent 05aefff23f
commit 26806438b7
4 changed files with 44 additions and 13 deletions

View file

@ -7,5 +7,6 @@
"databasePort": 3306, "databasePort": 3306,
"databaseUsername": "username", "databaseUsername": "username",
"databasePassword": "password", "databasePassword": "password",
"databaseName": "osu!" "databaseName": "osu!",
"databaseKey": "examplekey"
} }

12
osu!.sql Normal file → Executable file
View file

@ -46,7 +46,8 @@ CREATE TABLE `users_info` (
`supporter` tinyint(1) NOT NULL, `supporter` tinyint(1) NOT NULL,
`web_session` varchar(64) NOT NULL, `web_session` varchar(64) NOT NULL,
`verification_needed` tinyint(1) NOT NULL DEFAULT '0', `verification_needed` tinyint(1) NOT NULL DEFAULT '0',
`password_change_required` tinyint(1) NOT NULL `password_change_required` tinyint(1) NOT NULL,
`has_old_password` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1; ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `users_modes_info` ( CREATE TABLE `users_modes_info` (
@ -91,6 +92,7 @@ CREATE TABLE `web_titles` (
`title` varchar(32) NOT NULL `title` varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1; ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `scores` ALTER TABLE `scores`
ADD PRIMARY KEY (`id`); ADD PRIMARY KEY (`id`);
@ -111,9 +113,13 @@ ALTER TABLE `web_titles`
ADD PRIMARY KEY (`id`); ADD PRIMARY KEY (`id`);
ALTER TABLE `scores`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0;
ALTER TABLE `users_info` ALTER TABLE `users_info`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=100;
ALTER TABLE `users_modes_info` ALTER TABLE `users_modes_info`
MODIFY `n` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0; MODIFY `n` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=0;
INSERT INTO `web_info` (`i`, `HomepageText`) VALUES ('0', 'A default Binato instance!'); INSERT INTO `web_info` (`i`, `HomepageText`) VALUES ('0', 'A default Binato instance!');

View file

@ -8,6 +8,7 @@
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"aes256": "^1.1.0",
"chalk": "^4.1.0", "chalk": "^4.1.0",
"compression": "^1.7.4", "compression": "^1.7.4",
"express": "^4.17.1", "express": "^4.17.1",

View file

@ -1,21 +1,28 @@
const osu = require("osu-packet"); const osu = require("osu-packet"),
aes256 = require("aes256"),
config = require("../config.json");
module.exports = { module.exports = {
checkLogin:async function(loginInfo) { checkLogin:async function(loginInfo) {
// Queue up incorrect login response
const incorrectDetailsResponse = incorrectLoginResponse();
// Check if there is any login information provided // Check if there is any login information provided
if (loginInfo == null) return incorrectDetailsResponse; if (loginInfo == null) return incorrectLoginResponse();
const userDBData = await global.DatabaseHelper.query(`SELECT * FROM users_info WHERE username = "${loginInfo.username}" LIMIT 1`); const userDBData = await global.DatabaseHelper.query(`SELECT * FROM users_info WHERE username = "${loginInfo.username}" LIMIT 1`);
// Make sure a user was found in the database // Make sure a user was found in the database
if (Object.keys(userDBData).length < 1) return incorrectDetailsResponse; if (Object.keys(userDBData).length < 1) return incorrectLoginResponse();
// Make sure the username is the same as the login info // Make sure the username is the same as the login info
if (userDBData.username !== loginInfo.username) return incorrectDetailsResponse; if (userDBData.username !== loginInfo.username) return incorrectLoginResponse();
// Make sure the password is the same as the login info // If the user has an old md5 password
if (userDBData.password !== loginInfo.password) return incorrectDetailsResponse; if (userDBData.has_old_password == 1) {
// Make sure the password is the same as the login info
if (userDBData.password !== loginInfo.password) return incorrectLoginResponse();
return requiredPWChangeResponse();
} else {
if (aes256.decrypt(config.databaseKey, userDBData.password) !== loginInfo.password) return incorrectLoginResponse();
}
return null; return null;
} }
} }
@ -33,4 +40,20 @@ function incorrectLoginResponse() {
'Content-Type': 'text/html; charset=UTF-8' 'Content-Type': 'text/html; charset=UTF-8'
} }
]; ];
}
function requiredPWChangeResponse() {
const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.Announce("As part of migration to a new password system you are required to change your password. Please login on the website and change your password.");
osuPacketWriter.LoginReply(-1);
return [
osuPacketWriter.toBuffer,
{
'cho-token': 'No',
'cho-protocol': global.protocolVersion,
'Connection': 'keep-alive',
'Keep-Alive': 'timeout=5, max=100',
'Content-Type': 'text/html; charset=UTF-8'
}
];
} }