My login with AJAX and PHP
Since throw interrupts the program flow, you don't need to provide an else branch. That way, you also visibly follow the good practice of using 'watchdogs':

&lt;?php

include_once('config.php');
include_once(ROOT . 'libs/database.php');
include_once(ROOT . 'libs/models/user.php');

class Security
{

    //...

    public static function TryLogin($username, $password)
    {
        $username = strtolower($username);
        $password = sha1($password . $username);

        $conn = Database::getConnection();
        if (empty($conn)) {
            throw new Exception('The connection to the database failed.');
        }

        $result = odbc_exec($conn, '{CALL [BruPartsOrderDb].[dbo].[tryLogin]("' . $username . '", "' . $password . '")}');
        if (empty($result)) {
            throw new Exception('The execution of the query failed.');
        }

        $row = odbc_fetch_row($result);
        if (empty($row)) {
            throw new Exception('Username or password incorrect.');
        }

        if (session_id() == '') {
            session_start();
        }

        $_SESSION['user'] = new User(odbc_result($result, 'id'), $username);

        return true;
    }

    //...
}


Suddenly the code looks much more handy.