1.3.x almost finished backport
This commit is contained in:
52
database/backported/1.3-beta2/changeAccountUsername.php
Normal file
52
database/backported/1.3-beta2/changeAccountUsername.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
$conn = newConnection();
|
||||
|
||||
$username = isset($_POST['username']) ? $_POST['username'] : '';
|
||||
$current_password = isset($_POST['currentPassword']) ? $_POST['currentPassword'] : '';
|
||||
$new_username = isset($_POST['newUsername']) ? $_POST['newUsername'] : '';
|
||||
|
||||
if (empty($username) || empty($new_username) || empty($current_password)) {
|
||||
die("-2");
|
||||
}
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9]{3,16}$/', $new_username)) {
|
||||
die("-3");
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
|
||||
$stmt->bind_param("s", $username);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
$user = $result->fetch_assoc();
|
||||
if (!password_verify($current_password, $user['password'])) {
|
||||
die("-6");
|
||||
}
|
||||
} else {
|
||||
die("-7");
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
|
||||
$stmt->bind_param("s", $new_username);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
die("-8");
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("UPDATE users SET username = ? WHERE username = ?");
|
||||
$stmt->bind_param("ss", $new_username, $username);
|
||||
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
|
||||
echo '1';
|
||||
|
||||
?>
|
||||
47
database/backported/1.3-beta2/loginAccount.php
Normal file
47
database/backported/1.3-beta2/loginAccount.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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'];
|
||||
$savedata = json_decode($row['save_data'], true);
|
||||
$icon = $savedata['bird']['icon'] ?? 1;
|
||||
$overlay = $savedata['bird']['overlay'] ?? 0;
|
||||
|
||||
$stmt = $conn->prepare("UPDATE users SET latest_ip = ? WHERE id = ?");
|
||||
$stmt->bind_param("si", $login_ip, $uid);
|
||||
$stmt->execute();
|
||||
|
||||
echo "$token:$uid:$highscore:$icon:$overlay";
|
||||
} else {
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
exit("-2");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
exit("-2");
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user