PHP Login Authentication with BCrypt I have a php authentication script and everything works fine, but I'm very unsure about the way I programmed it (I hardcoded some things). I was hoping stack could look through this and point out any potential problems. Here's the script:

&lt;?php
require_once 'Bcrypt.php';
class Mysql {
    private $conn;

    function __construct() {
        $this-&gt;conn =  new PDO('mysql:host=***;dbname=***;charset=UTF-8','***','***') or 
                      die('There was a problem connecting to the database.');
    }

    function verify_Username_and_Pass($un, $pwd) {
        ini_set('display_errors', 'On');
        error_reporting(E_ALL | E_STRICT);
        $query = "SELECT *
                FROM Conference
                WHERE Username = :un";

        $stmt = $this-&gt;conn-&gt;prepare($query);

        $stmt-&gt;bindParam(':un', $un);
        //$stmt-&gt;bindParam(':pwd', $pwd);
        $stmt-&gt;execute();
        $row = $stmt-&gt;fetchAll();
        $hash = $row[0]["Password"];
        $is_correct = Bcrypt::check($pwd, $hash);

        if ($is_correct) {
            // User exist
            $firstName = $row[0]["First Name"];
            $_SESSION["FirstName"] = $firstName;
            return true;
            $stmt-&gt;close();
        }
        else {
            // User doesn't exist
            return false;
            $stmt-&gt;close();
        }
    }
}
?&gt;


So how does it look?
I've tried cleaning it up a bit here, removed instances of setting a variable once and using it directly below where it was set (yes, improves readability, but still). 

require_once 'Bcrypt.php';

class Mysql {
    private $conn;
    private $host    = 'host';
    private $dbName  = 'dbname'; 
    private $charset = 'UTF-8';
    private $checkUserQuery = 'SELECT * FROM Conference WHERE Username = :un';

    function __construct() {
        $this-&gt;conn =  new PDO('mysql:host=' . $this-&gt;host . ';dbname=' . $this-&gt;dbname . ';charset=' . $this-&gt;charset) 
                       or die('There was a problem connecting to the database.');
    }

    function verifyUsernameAndPass($un, $pwd) {
        $stmt = $this-&gt;conn-&gt;prepare($this-&gt;checkUserQuery);

        $stmt-&gt;bindParam(':un', $un);
        #$stmt-&gt;bindParam(':pwd', $pwd);
        $stmt-&gt;execute();
        $row = $stmt-&gt;fetchAll();
        $stmt-&gt;close(); # Moved up, so closes before we return/exit function

        # You're setting $hash here, and using it directly below.
        # See new code below
        //$hash = $row[0]['Password'];
        //$is_correct = Bcrypt::check($pwd, $hash);

        //if ($is_correct) {
        if( Bcrypt::check($pwd, $row[0]['Password']) ){
            # User exist

            # You're setting $firstName once, and using it directly below it.
            # See new code below
            //$firstName = $row[0]['First Name']; 
            //$_SESSION['FirstName'] = $firstName;

            $_SESSION['FirstName'] = $row[0]['First Name'];

            return true;
        } else {
            # User does not exist
            return false;
        }
    }
}


And here's the same code, without my comments:

require_once 'Bcrypt.php';

class Mysql {
    private $conn;
    private $host    = 'host';
    private $dbName  = 'dbname'; 
    private $charset = 'UTF-8';
    private $checkUserQuery = 'SELECT * FROM Conference WHERE Username = :un';

    function __construct() {
        $this-&gt;conn =  new PDO('mysql:host=' . $this-&gt;host . ';dbname=' . $this-&gt;dbname . ';charset=' . $this-&gt;charset) 
                       or die('There was a problem connecting to the database.');
    }

    function verifyUsernameAndPass($un, $pwd) {
        $stmt = $this-&gt;conn-&gt;prepare($this-&gt;$checkUserQuery);

        $stmt-&gt;bindParam(':un', $un);
        $stmt-&gt;execute();
        $row = $stmt-&gt;fetchAll();
        $stmt-&gt;close();

        if( Bcrypt::check($pwd, $row[0]['Password']) ){ # User exists
            $_SESSION['FirstName'] = $row[0]['First Name'];
            return true;
        } else { # User does not exist
            return false;
        }
    }
}