I'm not very educated on PHP or Web-security in general, but i strongly suspect that the code generated by some software the company I'm working for is using, is unsafe.
Here are some snippets of what i am concerned about:
First concern:
$sql = "SELECT password, fullname FROM ".$mysql_table."
WHERE username = '".mysqli_real_escape_string($db,$_POST['username'])."'";
Is it bad to retrieve the password for the given username and then comparing them in the PHP, or is it better practice to use the password in the query itself, something like this:
... WHERE username = $username AND password = $hashed_password
Second concern:
$crypt_pass = md5($_POST['password']);
if ($crypt_pass == $data['password'])
{
//LOGIN SUCCESS
}
Is using md5-hashing and not using salt, enough?
Third concern:
setcookie('username', $_POST['username'], time() + 3600*24*30);
setcookie('password', $_POST['password'], time() + 3600*24*30);
Is it a good idea to store plain/text usernames and passwords in a cookie?
Is any of this code unsafe and if so, what should be done instead?