I made the changes you suggested I think.
There are still a few possible improvements. For example, there is still a flow of control where $u_password is used by not defined. mysql_numrows() is deprecated and should be mysql_num_rows(). I would suggest something along the lines of:
<?php
require_once 'config.php';
require_once 'session.php'; // move sessions to database
require_once 'functions.php'; // contains all functions used by the cms
if (!isset($_SESSION['user'])) // if user is not logged in
{
// if username and password was filled in the form
if (isset($_POST['u_name'], $_POST['u_password']))
{
$u_name = strtolower($_POST['u_name']);
$u_password = md5($_POST['u_password']); // hash the password to compare to DB
if (!dbConnect()) // attempt to connect to database
{
exit('Error connecting to database');
}
$login_user = $u_name;
$u_name = mysql_real_escape_string($u_name);
$query = "SELECT superadmin FROM cmsusers
WHERE `user` = '$u_name' AND `pass` = '$u_password' AND `enabled` = '1' LIMIT 1";
$result = mysql_query($query) or die;
$user_exist = mysql_num_rows($result);
if($user_exist > 0) //if a user and the password match a user in the database
{
$login_level = mysql_result($result, 0, "superadmin");
setSessionVariable("user", $login_user);
setSessionVariable("superadmin", $login_level); // will be 0 1 or 2
}
else // if a matching user was not found
{
session_unregister("user");
require_once 'login_error_form.php';
exit;
}
}
if (!isset($_SESSION['user'])) // if no user is set display a login form
{
require_once 'login_form.php';
exit;
}
}
?>
SHA1 is on its way out. See, e.g.: http://csrc.nist.gov/groups/ST/toolk...ents-final.pdf
Note that the type of attack is the same as MD5: being able to construct two distinct messages with the same hash (which isn't the same as being able to construct a message for an arbitrary given hash).
That is what I mean by lack of substantiation: SHA-1 is broken for collision attacks, not preimage attacks, but preimage attacks are what this kind of password hashing is concerned with. So, why choose MD5 when you can choose SHA-1? The phpBB3 devs just insist that MD5 is in the same boat as SHA-1, thus it does not matter, but it seems that this boat that they are referring to is the "broken for collision attacks" boat.
NIST recommends something from the SHA-2 family (SHA-224, -256, etc.) as being "good enough for government work"; at least until the winner of the current hash competition is determined.
Unfortunately PHP4 is not yet obsolete, so some people (phpBB3, valeryan) might want to continue supporting a PHP4.4 installation out of the box, and consequently the hash extension might not be available, but sha1() surely would be available.