<?php
include("connect.php");
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Username and password sent from form in HTML
$myusername = $_POST['username'];
$mypassword = $_POST['password'];
$sql = "SELECT id FROM users WHERE username='$myusername' and password='$mypassword'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$active = $row['active'];
$count = mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if ($count == 1) {
session_register("myusername");
$_SESSION['login_user'] = $myusername;
header("location: welcome.php");
} else {
$error = "Your username or password is invalid";
}
}
?>
This is my current login code. On my registration page, I have it so that when it injects into the database, it injects the passwords already encrypted in MD5. However, I cannot seem to convert:
$mypassword=$_POST['password'];
Into MD5 to confirm to see if the password exists in the database. With this code, the passwords must not be encrypted. What should I change to make it so that it checks with the database encrypted?
$mypassword=md5($_POST['password']);? - Royal Bgmd5($_POST['password'])in database and compare it also to the hashed password when logging in. - MarkPBKDF2,Rfc2898DeriveBytes,password_hash,Bcrypt,passlib.hashor similar functions. The point is to make the attacker spend a substantial of time finding passwords by brute force. - zaph