summaryrefslogtreecommitdiff
path: root/public/account
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-05-03 16:51:41 +0500
committerilotterytea <iltsu@alright.party>2025-05-03 16:51:41 +0500
commit5118aa3a7c99bb5655957cd50807ba32493e3c68 (patch)
tree3b8cf9ddda3abd06b433df417bf79d850f8a05b8 /public/account
parent1dd6e790fc87b6d4649fead8d319def9b1518801 (diff)
feat: check for username duplicates
Diffstat (limited to 'public/account')
-rw-r--r--public/account/login/twitch.php7
1 files changed, 7 insertions, 0 deletions
diff --git a/public/account/login/twitch.php b/public/account/login/twitch.php
index f322f42..05093cd 100644
--- a/public/account/login/twitch.php
+++ b/public/account/login/twitch.php
@@ -104,6 +104,13 @@ if ($row = $stmt->fetch()) {
$user_name = $twitch_user["login"];
$user_id = bin2hex(random_bytes(16));
+ // checking for duplicates
+ $stmt = $db->prepare("SELECT COUNT(*) FROM users WHERE username = ?");
+ $stmt->execute([$user_name]);
+ $duplicates = intval($stmt->fetch()[0]);
+ if ($duplicates > 0) {
+ $user_name .= $duplicates + 1;
+ }
$stmt = $db->prepare("INSERT INTO users(id, username, secret_key) VALUES (?, ?, ?)");
if (!$stmt->execute([$user_id, $user_name, $user_secret_key])) {