Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/114790-login-stystem-help/
Share on other sites

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
?>

Link to comment
https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590256
Share on other sites

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']);

Link to comment
https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590274
Share on other sites

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
?>


Link to comment
https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590303
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/114790-login-stystem-help/#findComment-590328
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.