Can someone look at the code below and just tell me if there's any major flaws in it? Is it safe?
//Get results out of form input and make into SAFE variables, lowercase if text. Uppercase of postcode.
$loginname = mysql_real_escape_string(strtolower($POST["loginconame"]));
$loginpostcode1 = mysql_real_escape_string(strtoupper($POST["loginpostcode1"]));
$loginpostcode2 = mysql_real_escape_string(strtoupper($POST["loginpostcode2"]));
$loginpassword = mysql_real_escape_string(strtolower($POST["loginpassword"]));
//take info from the row of data where coname is what the user inputted
$result = mysql_query("SELECT * FROM table WHERE name='$loginconame' && postcode1='$loginpostcode1' && postcode2='$loginpostcode2'") or die(mysql_error());
$row = mysql_fetch_array( $result );
//check hashed pw's match
$hash = hash("sha256","myverylongandrandomletterswhichichangedforonhere".$loginpassword.$row['foo']);
//if login name, pw and goc number all correct, allow to proceed.
if($row['name']==$loginconame && $row['postcode1']==$loginpostcode1 && $row['postcode2']==$loginpostcode2 && $row['password']==$snphash && $row['active']=="on")
{...proceed...}
else {echo "failed";}
I could change the * to specify just the bits i need from the table, but does matter?
My main concern, is that the script is looking up details from the table before I've really checked against the password. This is because I've a 'salt' specific for that user in the table.