I've a registration form as well as login form. I've used md5 encryption in my registration form and it's working fine. But when I'm trying to login with real password like (123) it's not logging me in. On the other hand, when I copy paste that md5 encryption in password field, it's then logging me in. Please help me about this! Thank you!
Here is my coding:
<?php
if (isset($_POST['submit'])) {
$user_name = $_POST['username'];
$user_email = $_POST['email'];
$user_pass = $_POST['password'];
$query = "SELECT * FROM users where Email = '" . $_POST["email"] . "'";
$result = $obj->run_query($query);
if ($count = mysqli_num_rows($result) == 0) {
$query = "INSERT INTO users (Name,Email,Pass) VALUES ('$user_name','$user_email', md5('$user_pass'))";
$result = $obj->run_query($query);
echo "<script>alert('You have successfully Registered!')</script>";
echo "<script>window.open('welcome.php','_self')</script>";
} else {
echo "<script>alert('This user email $user_email is already exist!')</script>";
}
}
// login script
if (isset($_POST['login'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['pass'];
$query = "SELECT * FROM users WHERE Email = '$email' AND Pass = '$password'";
$result = $obj->run_query($query);
if ($count = mysqli_num_rows($result) > 0) {
$_SESSION['email'] = $email;
$_SESSION['name'] = $name;
echo "<script>window.open('welcome.php','_self')</script>";
}
else
{
echo "<script>alert('Your email or password is incorrect!')</script>";
}
}
?>