Move backported files
This commit is contained in:
44
database/backported/1.2-beta2/loginAccount.php
Normal file
44
database/backported/1.2-beta2/loginAccount.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
$conn = newConnection();
|
||||
|
||||
$request_username = $_POST['username'];
|
||||
$request_password = $_POST['password'];
|
||||
|
||||
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
|
||||
$stmt->bind_param("s", $request_username);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
while($row = $result->fetch_assoc()) {
|
||||
if (password_verify($request_password, $row["password"])) {
|
||||
$login_ip = getIPAddress();
|
||||
$login_time = time();
|
||||
$uid = $row['id'];
|
||||
$username = $row['username'];
|
||||
$highscore = $row['legacy_high_score'];
|
||||
$token = $row['token'];
|
||||
|
||||
$stmt = $conn->prepare("UPDATE users SET latest_ip = ? WHERE id = ?");
|
||||
$stmt->bind_param("si", $login_ip, $uid);
|
||||
$stmt->execute();
|
||||
|
||||
echo "$token:$uid:$highscore";
|
||||
} else {
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
exit("-2");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
exit("-2");
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
|
||||
?>
|
||||
45
database/backported/1.2-beta2/registerAccount.php
Normal file
45
database/backported/1.2-beta2/registerAccount.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
$conn = newConnection();
|
||||
|
||||
$username = $_POST['username'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
$email = $_POST['email'] ?? '';
|
||||
|
||||
if (empty($username) || empty($password) || empty($email)) {
|
||||
exit("-2");
|
||||
}
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9]{3,16}$/', $username)) {
|
||||
exit("-3");
|
||||
}
|
||||
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
exit("-4");
|
||||
}
|
||||
|
||||
if (!preg_match('/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!@#$%^&*()_\-+=]{8,}$/', $password)) {
|
||||
exit("-5");
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
|
||||
$stmt->bind_param("ss", $username, $email);
|
||||
$stmt->execute();
|
||||
$res = $stmt->get_result();
|
||||
|
||||
if ($res->num_rows > 0) {
|
||||
exit("-7");
|
||||
}
|
||||
|
||||
$hashed = password_hash($password, PASSWORD_DEFAULT);
|
||||
$token = bin2hex(random_bytes(256));
|
||||
$ip = getIPAddress();
|
||||
$time = time();
|
||||
|
||||
$stmt = $conn->prepare("INSERT INTO users (token, username, password, email, register_time, latest_ip) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
$stmt->bind_param("ssssis", $token, $username, $hashed, $email, $time, $ip);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
|
||||
echo '1';
|
||||
25
database/backported/1.2-beta2/syncAccount.php
Normal file
25
database/backported/1.2-beta2/syncAccount.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
$conn = newConnection();
|
||||
|
||||
$request_uid = $_POST['userID'] ?? 0;
|
||||
$request_session = $_POST['gameSession'] ?? '';
|
||||
$request_score = $_POST['highScore'] ?? 0;
|
||||
|
||||
$stmt = $conn->prepare("SELECT * FROM users WHERE token = ? AND id = ?");
|
||||
$stmt->bind_param("ss", $request_session, $request_uid);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
$updateStmt = $conn->prepare("UPDATE users SET legacy_high_score = ? WHERE token = ? AND id = ?");
|
||||
$updateStmt->bind_param("isi", $request_score, $request_session, $request_uid);
|
||||
$updateStmt->execute();
|
||||
echo 1;
|
||||
$updateStmt->close();
|
||||
} else {
|
||||
echo "-2";
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
?>
|
||||
Reference in New Issue
Block a user