This is invalid code
[php]if (isset($_POST[‘username’]) and isset($_POST[‘password’])); [/php]
Should be:
[php]if (isset($_POST[‘username’]) and isset($_POST[‘password’]))[/php]
Though I prefer
[php]if (isset($_POST[‘username’]) && isset($_POST[‘password’]))[/php]
[hr]
You can combine this code
[php] $stmt->bindParam(’:username’, $_POST[‘username’], PDO::PARAM_STR);
$stmt->bindParam(’:password’, $enc_pwd, PDO::PARAM_STR);
// execute prepared query
$stmt->execute();[/php]
Into
[php] // execute prepared query
$stmt->execute(array(
‘username’ => $_POST[‘username’],
‘password’ => $enc_pwd
));[/php]
[hr]
This is not encryption
[php] // encrypt password and store in a temporary variable
$enc_pwd = sha1($_POST[‘password’]);[/php]
Might be arguing over semantics for some, but I think it’s important to differentiate password hashing from encryption as they’re not really the same at all. And even if person A and B knows a “encrypted password” is a hash, person C might not.
[hr]
Please use the PHP password lib to handle passwords in a secure manner.
http://php.net/manual/en/function.password-hash.php