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
Share on other sites

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.

Link to comment
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.