Jump to content

Help with logging in php


turkman

Recommended Posts

Hey Guys ive wrote this logging in script but im not sure why it isnt logging in

 

ive added echos too see what two strings the strcmp is comparing and the output is this

 

Admin 05957a3ee71e1ea8a059460b60647b3e

pass = 05957a3ee71e1ea8a059460b60647b3e

Login Failed Click Here To Continue

 

Now both those hashed passwords seem to match so why isnt it logging in?

 

if(isset($_GET['d'])){

  //try loging
  if(isset($_POST['uname']) AND isset($_POST['pass'])){
  
    $u = protect($_POST['uname']);
    $p = md5($_POST['pass']);
    
    echo $u ." " . $p . "   <br>";
    //now to login
    $val = "SELECT * FROM pword WHERE uname = '$u'";
      $res = mysql_query($val) or die (mysql_error());
       $numrows = mysql_num_rows($res);
     
       If($numrows < 1) 
       { $_SESSION['LOGINSTATUS'] = "INVALID"; echo "<a href = 'index.php'> Login Failed: Click Here To continue blah vlah</a>";}      
       
       while($row = mysql_fetch_array($res , MYSQL_ASSOC))
        {
        if(strcmp($row['pass'],$pass)==0){ 
        
        echo "<pass = " . $row['pass'];
        $_SESSION['uname'] =$row['uname'];
        $_SESSION['ID']= $row['ID'];
         $_SESSION['LOGINSTATUS'] = "VALID";
    
        echo "<a href = 'index.php'>Login Accepted Click Here To Continue</a>";
        }
        
        else{ 
        echo "pass = " . $row['pass'] ."<br>";
        
        echo "<a href = 'index.php'>Login Failed Click Here To Continue</a>";
        }
        
       }
  
  
  }
  
  //header("Location: index.php");
  
  



}

 

Link to comment
https://forums.phpfreaks.com/topic/193846-help-with-logging-in-php/
Share on other sites

  Quote

Hey Guys ive wrote this logging in script but im not sure why it isnt logging in

 

ive added echos too see what two strings the strcmp is comparing and the output is this

 

Admin 05957a3ee71e1ea8a059460b60647b3e

pass = 05957a3ee71e1ea8a059460b60647b3e

Login Failed Click Here To Continue

 

Now both those hashed passwords seem to match so why isnt it logging in?

 

if(isset($_GET['d'])){

  //try loging
  if(isset($_POST['uname']) AND isset($_POST['pass'])){
  
    $u = protect($_POST['uname']);
    $p = md5($_POST['pass']);
    
    echo $u ." " . $p . "   <br>";
    //now to login
    $val = "SELECT * FROM pword WHERE uname = '$u'";
      $res = mysql_query($val) or die (mysql_error());
       $numrows = mysql_num_rows($res);
     
       If($numrows < 1) 
       { $_SESSION['LOGINSTATUS'] = "INVALID"; echo "<a href = 'index.php'> Login Failed: Click Here To continue blah vlah</a>";}      
       
       while($row = mysql_fetch_array($res , MYSQL_ASSOC))
        {
        if(strcmp($row['pass'],$pass)==0){ 
        
        echo "<pass = " . $row['pass'];
        $_SESSION['uname'] =$row['uname'];
        $_SESSION['ID']= $row['ID'];
         $_SESSION['LOGINSTATUS'] = "VALID";
    
        echo "<a href = 'index.php'>Login Accepted Click Here To Continue</a>";
        }
        
        else{ 
        echo "pass = " . $row['pass'] ."<br>";
        
        echo "<a href = 'index.php'>Login Failed Click Here To Continue</a>";
        }
        
       }
  
  
  }
  
  //header("Location: index.php");
  
  



}

 

 

You have your strcmp backwards.

 

 

if (strcmp($pw1, $pw2)) {  // This returns false.

    // $pw1 and $pw2 are NOT the same.

} else {

    // $pw1 and $pw2 are the same.

}

 

Try flipping it around and see what happens.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.