PDO Login/Register system review I wrote my very first login/register PDO system today.  I know there is still a lot of flaws, but I was wondering what tips and advice you have to help me improve this. I know that PDO is much more secure than MySQl, so would you say my code is secure?  If so, to what extent, since I'm using PDO?  Any tips and advice would be much appreciated! 

login.php

&lt;h1&gt;Login&lt;/h1&gt;
&lt;form method="POST"&gt;
    &lt;input type="text" name="username"&gt;&lt;br /&gt;
    &lt;input type="password" name="password"&gt;&lt;br /&gt;
    &lt;input type="submit"&gt;
&lt;/form&gt;

&lt;?php
session_start();
    if(isset($_POST['username'], $_POST['password'])){
        require 'core/connect.php';

        $query = dbConnect()-&gt;prepare("SELECT username, password FROM users WHERE username=:username AND password=:password");
        $query-&gt;bindParam(':username', $_POST['username']);
        $query-&gt;bindParam(':password', $_POST['password']);
        $query-&gt;execute();

        if($row = $query-&gt;fetch()){
            $_SESSION['username'] = $row['username'];
            header("Location: index.php");
        }
    }
?&gt;


register.php

&lt;h1&gt;Register&lt;/h1&gt;
&lt;form method="POST"&gt;
    &lt;input type="text" name="username"&gt;&lt;br /&gt;
    &lt;input type="password" name="password"&gt;&lt;br /&gt;
    &lt;input type="submit"&gt;
&lt;/form&gt;

&lt;?php
session_start();

    if(isset($_POST['username'], $_POST['password'])){
        require 'core/connect.php';

        $query = dbConnect()-&gt;prepare("INSERT INTO users (username, password) VALUES (:username, :password)");
        $query-&gt;bindParam(':username', $_POST['username']);
        $query-&gt;bindParam(':password', $_POST['password']);

        if($query-&gt;execute()){
            header("Location: index.php");
        } else{
            echo 'ERROR';
        }
    }
?&gt;


index.php

&lt;?php
session_start();

if(isset($_SESSION['username'])){
    echo 'Welcome!', '&lt;a href="logout.php"&gt;Logout&lt;/a&gt;';
} else {
    echo '&lt;a href="login.php"&gt;Login&lt;/a&gt;&lt;br /&gt;
    &lt;a href="register.php"&gt;Register&lt;/a&gt;';
}
?&gt;


core/connect.php

&lt;?php
    function dbConnect(){
        try{
            $username = 'root';
            $password = '';
            $conn = new pdo("mysql:host=localhost;dbname=test;", $username, $password);
            $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            return $conn;

        }   catch(PDOException $e){
            echo 'ERROR', $e-&gt;getMessage();
        }
    }
?&gt;
Here are several tips:


Use OOP - this way you could start the session only once
Hash your passwords - this way no one can steal it from the db, or at least the chance is lower
Use MVC - separate your HTML from the PHP code
Move your db connect credentials to the .ini file - this way it could be easily changed and .ini files can be cached by the server


Feel free to check my code for user authorization here in my pet project.