I've created a login page and I'm using Cookies. Down below is the code for Login Page:
Register<?php
session_start();
if(isset($_POST['submitted'])){
$errors = array();
$mysqli = new mysqli('localhost', 'db123', 'db123', 'db123');
$username = $_POST['username'];
$result = $mysqli->query("SELECT * FROM registered_users WHERE phone_number = '$username'");
$data = mysqli_fetch_assoc($result);
if($result->num_rows == 0) {
echo 'Username Not Found!';
} elseif($data['otp_verified'] === 'false'){
echo 'OTP Not Verified, Click Here To Verify Your Number';
}
else{
$encryptpass=md5($_POST['password']);
$cookie_username = $_POST['username'];
if($encryptpass == $data['password']){
echo 'Login Is Verified';
$Month = 86400 + time();
setcookie('user', $cookie_username, $Month);
header("location:dashboard.php");
}
else{
echo 'Login/Password Incorrect :(';
}
}
$mysqli->close();
}
?>
And Finally, Here's the code for dashboard.php and all other pages which are restricted:
<?php
session_start();
if(!isset($_COOKIE['user']))
{
header("location:index.php");
die();
}
?>
My Questions: 1. How Secure Is This Login System? 2. How I can improve it? Thanks in advance :)