fixed invalid register username problems

This commit is contained in:
Václav Šmejkal 2024-05-21 19:20:18 +02:00
parent 2a3f639a66
commit 888c7a5019
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -66,12 +66,23 @@ session_start();
if (str_starts_with($_POST["sub"], "Registrovat")) if (str_starts_with($_POST["sub"], "Registrovat"))
{ {
$failed = false;
$database -> query("INSERT INTO user_info (nickname) VALUES (\"" . $safe_uname . "\")"); $database -> query("INSERT INTO user_info (nickname) VALUES (\"" . $safe_uname . "\")");
$key_id_out = $database -> query("SELECT id FROM user_info WHERE nickname=\"" . $safe_uname . "\""); $key_id_out = $database -> query("SELECT id FROM user_info WHERE nickname=\"" . $safe_uname . "\"");
$database -> query("INSERT INTO user (username, password, user_info) VALUES (\"" . $safe_uname . "\",\"" . $hashed_pass ."\", " . ($key_id_out -> fetch_assoc())["id"] . ")"); try
{
$database -> query("INSERT INTO user (username, password, user_info) VALUES (\"" . $safe_uname . "\",\"" . $hashed_pass ."\", " . ($key_id_out -> fetch_assoc())["id"] . ")");
} catch (mysqli_sql_exception $e)
{
$failed = true;
$database -> query("DELETE FROM user_info WHERE nickname=\"" . $safe_uname . "\"");
login($safe_uname); echo "<script>alert(\"Při registraci došlo k chybě.\\n\\nZkontrolujte, zda-li Vaše uživatelské jmeno neobsahuje speciální znaky a zkuste to znovu.\");</script>";
}
if (!$failed) login($safe_uname);
} else } else
{ {
$res = $database -> query("SELECT username, password FROM user WHERE BINARY username=\"" . $safe_uname . "\" AND BINARY password = \"" . $hashed_pass . "\""); $res = $database -> query("SELECT username, password FROM user WHERE BINARY username=\"" . $safe_uname . "\" AND BINARY password = \"" . $hashed_pass . "\"");