I am writing an application for work. This application will sit on a closed network but I still have to be concerned about security. There will be a maximum of three types of user for this application: User (read only), admin (data edits only) and super admin (access all areas). But at the moment I am trying to get a feel for security on a basic level.
Just so I am clear about the user options: I meant that only 3 people will be permitted to use the application. So, there will only ever be ONE basic "User" and not a number of basic users.
Would one of you kind people please look at the following code to review its efficiency and security with the possibility of offering some tips on improvement.
function loginUser($username, $password)
{
include('assets/con.php');
/* Set the salt. */
$salt = 'JwethYGkuuygTYFIYTFrfkuyGUTf75kUY4uyk6';
/* Apply SHA512 password and salt encryption. */
$password = hash('SHA512', $password);
$salt = hash('SHA512', $salt);
$query = 'SELECT username FROM users WHERE username = ? AND password = ? AND pass_salt = ?';
if( $statement = $con->prepare($query) )
{
$statement -> bind_param( 'sss', $username, $password, $salt );
$statement -> execute();
$statement -> store_result();
$num_row = $statement -> num_rows;
$statement -> bind_result($username);
$statement -> fetch();
$statement -> close();
}
else die( "Failed to prepare query." );
if( $num_row === 1 )
{
$_SESSION['userName'] = $username;
return true;
}
return false;
}