I have wrote a simple login script and was wondering if it is secure and if not, how insecure is it.
The Login Script:
PHP Code:
require("../config/config.php");
$connection = mysql_connect("$host", "$usr", "$pwd")or die("cannot connect");
mysql_select_db("$db")or die("cannot select DB");
$username = mysql_real_escape_string(strip_tags($_POST['username']));
$password = mysql_real_escape_string(strip_tags($_POST['password']));
$query = mysql_query("SELECT * FROM users WHERE username ='$username' and password = '$password'");
$count = mysql_num_rows($query);
if($count==1){
session_register('username');
session_register('password');
$_SESSION['username'] = $username;s
$_SESSION['password'] = $password;
header("location:welcome.php");
}
else {
header("location:error.php");
}
The login checking at the top of each file:
PHP Code:
require('../config/config.php');
$username = $_SESSION['username'];
$password = $_SESSION['password'];
if (!session_is_registered("username") and !session_is_registered("password"))
{
header("location:error.php");exit;
}
$connection = mysql_connect($host,$usr,$pwd);
$query = mysql_db_query($db, "SELECT * from users where username = '$username' and password = '$password'", $connection);
$row = mysql_fetch_assoc($query);
$u = $row["username"];
$p = $row["password"];
if($u != $username or $p != $password ){
header("location:error.php");exit;}