Skip to content
Snippets Groups Projects
Commit af5fcf7a authored by Iqbal's avatar Iqbal
Browse files

Fixed unnecessary alert dan other bugs.

parent e0ace229
2 merge requests!7Routing Configuration with index.php,!6Reconfigure Login and Register Page
......@@ -14,6 +14,8 @@ class LoginController
{
session_start();
$userData = null;
if (isset($_POST['username'])) {
$username = $_POST['username'];
$password = md5($_POST['password']);
......@@ -27,14 +29,15 @@ class LoginController
exit;
}
if (isset($userData)) {
if ($userData !== null && $userData instanceof User) {
if ($userData->password === $password) {
$_SESSION['username'] = $username;
echo "<script type='application/javascript'> alert('Login berhasil'); </script>";
} else {
echo "<script type='application/javascript'> alert('Username atau password salah'); </script>";
echo "<script type='application/javascript'> alert('Password salah.'); </script>";
}
} else if ($userData !== null) {
echo "<script type='application/javascript'> alert('Username tidak terdaftar.'); </script>";
}
require __DIR__."/../view/login.php";
......
......@@ -70,7 +70,7 @@ class User {
$stmt = $conn->prepare("SELECT * FROM user WHERE $attribute='$value'");
$stmt->execute();
$user = $stmt->fetchObject();
$user = $stmt->fetchObject("User");
return $user;
} catch (PDOException $e) {
echo "Error: ".$e->getMessage();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment