***** User Login problem *****
Hello friends,
I've a user login system......user's name & password are saved in the database.......suppose i've an user "admin". At the time of login if he enters "admin" he can login also if enters "ADMIN" or "AdMiN" he can login too.....how can I stop this thing........PLZZZZZZZ show me the way......
thank you...
nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2
For that you could just convert both values to lower case with strtolower(); So try the following and I have included the form.
<?
//mysql connections
$username='Admin'; //from mysql in your script
$username=strtolower($username);
if (isset($_POST['username']))
{
$_POST['username']=strtolower($_POST['username']);
if ($_POST['username']==$username)
{
//login
}
}
?>
<form method='post'>
<input type='text' value='adMiN' name='username'>
<input type='submit' value='submit'>
</form>
cwarn23
Occupation: Genius
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
sorry man this is not that i want ......actually i want to check the string insterted case sensitive way......
nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2
If you want it case sensitive then because php is case sensitive, just get php to check if the 2 values = each other. So use the following:
<?
//mysql connections
$username='Admin'; //from mysql in your script
if (isset($_POST['username']) && $_POST['username']==$username)
{
//login
echo "test";
}
?>
<form method='post'>
<input type='text' value='adMiN' name='username'>
<input type='submit' value='submit'>
</form>
cwarn23
Occupation: Genius
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
according to your solution if I have 1,00,00,000 user will I define those user in that number of veriables ?????????? is this thing feasible ?????????
nil_gh_80
Junior Poster in Training
64 posts since Aug 2007
Reputation Points: 8
Solved Threads: 2
according to your solution if I have 1,00,00,000 user will I define those user in that number of veriables ?????????? is this thing feasible ?????????
Yes because all you need to do is check that the username (which should be unique from all the others) is correct and that at option, the password for security reasons is correct. So just to explain, I shall write a basic login system for you.
Below is login.php
session_start();
//mysql connect code
$result=mysql_query("SELECT * FROM `users` WHERE `username`='".$_POST['username']."' AND `password`='".$_POST['password']."'");
if (isset($_POST['username']) && mysql_num_rows($result)==1)
{
$row=mysql_fetch_array($result);
$_SESSION['username111']==$row['username'];
unset($row);
header('Location: index.php?login=true');
//there should be no browser output before this line.
}
?>
<form method='post'>
<input type='text' value='Admin' name='username'>
<input type='text' value='password' name='password'>
<input type='submit' value='submit'>
</form>
index.php (at top)
<?
session_start();
if ($_GET['login']=='true' && !isset($_SESSION['username111']))
{
echo "<h1>You need to be logged in to view this page!</h1>";
exit;
}
//no browser output before this line.
Sorry if there is a small bug but that login system is from the top of my head and I have used simular ones in the past. Hope that example helps
cwarn23
Occupation: Genius
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259