diff --git a/index.php b/index.php index 5448e69..4b07359 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,6 @@ + @@ -43,22 +46,50 @@
Přihlášen jako:
query("INSERT INTO user (username, password) VALUES (\"" . $safe_uname . "\",\"" . $hashed_pass ."\")"); - $database -> query("INSERT INTO user (username, password) VALUES (\"" . $safe_uname . "\",\"" . hash("sha256", $_POST["password"]) ."\")"); + login($safe_uname); } else { - echo "log"; + $res = $database -> query("SELECT username, password FROM user WHERE username=\"" . $safe_uname . "\" AND password = \"" . $hashed_pass . "\""); + + if ($res -> num_rows == 1) + { + login($safe_uname); + } else + { + echo ""; + } } } + + function login($uname) + { + if ($uname != null) + { + $_SESSION["username"] = $uname; + } else + { + $uname = $_SESSION["username"]; + } + + echo ""; + } ?>