asherinho Posted July 15, 2008 Share Posted July 15, 2008 I have a login form but It cant log in user if the user name is entered in capital letters.I used the trim() and addslashes() functions but still isn't working $uname=trim($_POST['uname']); $uname=addslashes($_POST['uname']); $pass=md5($_POST['pass']); which function is appropiate to use here? or what should I do? Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/ Share on other sites More sharing options...
Juan Dela Cruz Posted July 15, 2008 Share Posted July 15, 2008 <a href="http://www.php.net/manual/en/function.strtolower.php">strtolower</a> or <a href="http://www.php.net/manual/en/function.strtoupper.php">strtoupper</a> Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590204 Share on other sites More sharing options...
asherinho Posted July 15, 2008 Author Share Posted July 15, 2008 Is not working. $uname=strtolower($uname); $uname=trim($_POST['uname']); Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590217 Share on other sites More sharing options...
Juan Dela Cruz Posted July 15, 2008 Share Posted July 15, 2008 can you show us your code? Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590221 Share on other sites More sharing options...
corbin Posted July 15, 2008 Share Posted July 15, 2008 asherinho that code would be the equivalent of doing this a = f(b) a = f© where c does not always = a Look at your code, and look at the variables you're setting.... Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590234 Share on other sites More sharing options...
DeanWhitehouse Posted July 15, 2008 Share Posted July 15, 2008 try putting it the other way $uname=trim($_POST['uname']); $uname=strtolower($uname); Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590252 Share on other sites More sharing options...
asherinho Posted July 15, 2008 Author Share Posted July 15, 2008 Still isn't working Blade280891.here are the codes ?> $uname=trim($_POST['uname']); $uname=strtolower($uname); $pass=md5($_POST['pass']); if($uname != "" && $pass != ""){ if($_SESSION["logged_in_user"]==$uname && $_SESSION["logged_in_pass"]==$pass){ if($record["status"]=="administrator"){require("iframe_adm.php"); exit; }elseif($record["status"]=="user"){require("iframe_usr.php"); exit; } } require("connection.php"); $db=mysql_connect("$host","$user","$password"); if(!$db){echo "No connection,please contact the system administrator.Sorry";} mysql_select_db("$dbname",$db); $result=mysql_query("SELECT * FROM login WHERE uname='".$uname."' AND pass='".$pass."'"); if(!$result){echo "error in query";} if(mysql_num_rows($result) > 0){ $_SESSION["logged_in_user"]=$uname; $_SESSION["logged_in_pass"]=$pass; $record=mysql_fetch_assoc($result); if($record["status"]=="administrator"){require("iframe_adm.php"); exit; }elseif($record["status"]=="user"){require("iframe_usr.php"); exit; } } else{require("top.php"); echo "<B style='color:red;font-size:15px'>Wrong username or password</B>"; } if(!$db){echo "No connection,please contact the system administrator.Sorry";} }else{require("top.php"); echo "<B style='color:red;font-size:15px'>You forgot to enter the username or password ?> Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590256 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 //divide this line in 2 and debug... $strSql = "SELECT * FROM login WHERE uname='".$uname."' AND pass='".$pass."'"; echo $strSql; $result=mysql_query($strSql); fire the displayed query directly on database client and check if rows are returned.. Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590259 Share on other sites More sharing options...
asherinho Posted July 15, 2008 Author Share Posted July 15, 2008 I tried it samshel,it seems the the problem is on $pass,the encryption of password entered in uppercase is different from that in lowercase.I tried this but it didn't work $uname=trim($_POST['uname']); $uname=strtolower($uname); $pass=strtolower($pass); $pass=md5($_POST['pass']); Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590274 Share on other sites More sharing options...
DeanWhitehouse Posted July 15, 2008 Share Posted July 15, 2008 wrong way round $pass=md5($_POST['pass']); $pass=strtolower($pass); Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590277 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 while storing the username and password are you doing strtolower ? Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590279 Share on other sites More sharing options...
asherinho Posted July 15, 2008 Author Share Posted July 15, 2008 I reversed it Blade280891 but still there is nothing new.What do mean samshel? Here are the codes ?> $uname=trim($_POST['uname']); $uname=strtolower($uname); $pass=md5($_POST['pass']); if($uname != "" && $pass != ""){ if($_SESSION["logged_in_user"]==$uname && $_SESSION["logged_in_pass"]==$pass){ if($record["status"]=="administrator"){require("iframe_adm.php"); exit; }elseif($record["status"]=="user"){require("iframe_usr.php"); exit; } } require("connection.php"); $db=mysql_connect("$host","$user","$password"); if(!$db){echo "No connection,please contact the system administrator.Sorry";} $strSql = "SELECT * FROM login WHERE uname='".$uname."' AND pass='".$pass."'"; echo $strSql; $result=mysql_query($strSql); if(!$result){echo "error in query";} if(mysql_num_rows($result) > 0){ $_SESSION["logged_in_user"]=$uname; $_SESSION["logged_in_pass"]=$pass; $record=mysql_fetch_assoc($result); if($record["status"]=="administrator"){require("iframe_adm.php"); exit; }elseif($record["status"]=="user"){require("iframe_usr.php"); exit; } } else{require("top.php"); echo "<B style='color:red;font-size:15px'>Wrong username or password</B>"; } if(!$db){echo "No connection,please contact the system administrator.Sorry";} }else{require("top.php"); echo "<B style='color:red;font-size:15px'>You forgot to enter the username or password ?> Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590303 Share on other sites More sharing options...
DeanWhitehouse Posted July 15, 2008 Share Posted July 15, 2008 when ure addin them to the db , are u converting them to lowercase? Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590305 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 are the passwords manually added in DB or by some script, in that script, is the password lower cased ? Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590312 Share on other sites More sharing options...
asherinho Posted July 15, 2008 Author Share Posted July 15, 2008 All the values in the database are in lowercase I used the following query to enter the values into the databse INSERT INTO login(uname,pass,status) VALUES('admini',md5('ppra'),'administrator') Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590323 Share on other sites More sharing options...
DeanWhitehouse Posted July 15, 2008 Share Posted July 15, 2008 cant u just make sure that the pplz entering the username and password enter it lowercase? Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590326 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 you have done md5() on password in PHP while checking where as while entering you have used MySQL md5(), it should match, but just try shifting md5() in your code in query instead of PHP. <?php $uname=trim($_POST['uname']); $uname=strtolower($uname); $pass=$_POST['pass']; if($uname != "" && $pass != ""){ if($_SESSION["logged_in_user"]==$uname && $_SESSION["logged_in_pass"]==$pass){ if($record["status"]=="administrator"){require("iframe_adm.php"); exit; }elseif($record["status"]=="user"){require("iframe_usr.php"); exit; } } require("connection.php"); $db=mysql_connect("$host","$user","$password"); if(!$db){echo "No connection,please contact the system administrator.Sorry";} $strSql = "SELECT * FROM login WHERE uname='".$uname."' AND pass=md5('".$pass."')"; echo $strSql; $result=mysql_query($strSql); if(!$result){echo "error in query";} if(mysql_num_rows($result) > 0){ $_SESSION["logged_in_user"]=$uname; $_SESSION["logged_in_pass"]=$pass; $record=mysql_fetch_assoc($result); if($record["status"]=="administrator"){require("iframe_adm.php"); exit; }elseif($record["status"]=="user"){require("iframe_usr.php"); exit; } } else{require("top.php"); echo "<B style='color:red;font-size:15px'>Wrong username or password</B>"; } if(!$db){echo "No connection,please contact the system administrator.Sorry";} }else{require("top.php"); echo "<B style='color:red;font-size:15px'>You forgot to enter the username or password ?> check if it works. Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590328 Share on other sites More sharing options...
asherinho Posted July 15, 2008 Author Share Posted July 15, 2008 It is now working.Thank u samshel and all others.U are among the people who are making this forum usefull. Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590345 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 did the code i gave worked OR was there some other problem? also pl hit the solved button. Quote Link to comment https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590346 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.