Hi there.
I’ve just finished following sde’s tutorial on session authentication and have got it working successfully (after lowering the error reporting level to remove the issues where it gets upset about the undeclared ‘username’ and ‘password’).
However, I was wondering where exactly I would initiate some form of sanitisation to prevent users from injecting unwanted code into the fields (and of course prevent the resulting chaos afterwards).
My aim is to use LOWER for the username (as the username will always be characters only, lowercase) and to allow numeric, upper and lower case characters for the password. My issue is that Im not quite sure where I should be inserting the functions to verify the user input:
Code:
<?
// Login & Session example by sde
// auth.php
// start session
session_start();
// convert username and password from _POST or _SESSION
if($_POST){
$_SESSION['username']=$_POST["username"];
$_SESSION['password']=$_POST["password"];
}
// query for a user/pass match
$result=mysql_query("select * from users
where username='" . $_SESSION['username'] . "' and password='" . $_SESSION['password'] . "'");
// retrieve number of rows resulted
$num=mysql_num_rows($result);
// print login form and exit if failed.
if($num < 1){
echo "You are not authenticated. Please login.<br><br>
<form method=POST action=index.php>
username: <input type=text name=\"username\">
password: <input type=password name=\"password\">
<input type=submit>
</form>";
exit;
}
?>
Any help you could provide on this would be greatly appreciated, thank you.
- Fasc