检查电子邮件和密码是否正确


Check if is email and password correct

我需要确认电子邮件和密码是否正确,但它适用于我输入的任何密码。怎么了?这是代码:

<?php
if(isset($_POST['submit'])){
    $email = mysql_real_escape_string($_POST['email']);
$pass = $_POST['password'];
$hash = hash("sha512", $pass);
$hash1 = hash("whirpool", $hash);
$hash2 = hash("sha384", $hash1);
$password = $hash2;
    $query=mysql_query("SELECT * FROM register WHERE email='$email' AND password='$password'") or die(mysql_error());
    $count=mysql_num_rows($query);
 if($count==1){
    while ($row=mysql_fetch_array($query)) {
    $username=$row['username'];
  $heslo=$row['password'];
    $_SESSION['valid'] = $username;
if(isset($_SESSION['valid'])){
        $realtime = date("d-m-Y h:i:s"); 
        $session = $_SESSION['valid'];
        echo "<script>    window.location.replace('index.php');
</script>";
header("Location: index.php");
    }else{
        echo "Přihlášení neproběhlo správně";
    }
}
}
}
?>

您面临的问题是拼写错误的"whirpool"应该是"whirpol"

我对代码做了一些更改,这似乎起到了作用。花括号顺序是把它搞砸的顺序,因为其他顺序指向不正确的if.

我在整个剧本中添加了评论,所以你可以看到我想说什么。

mysql_connect('localhost','user','pass');
mysql_select_db('test');
# You can use your post methods, I've used these for testing.
$email = mysql_real_escape_string('email');
$pass = $_GET['pw'];

$hash = hash("sha512", $pass);
$hash1 = hash("whirlpool", $hash);
$hash2 = hash("sha384", $hash1);
$pass = $hash2;
# Now you can see the PW input  
echo $pass."<br>";
# Nonsense
$password = $pass;
    # By using $sql you can echo your query to see what results would it yield upon running it.
    $sql = "SELECT * FROM test WHERE em='$email' AND pw='$password'";
    $query=mysql_query($sql) or die(mysql_error());
    $count=mysql_num_rows($query);
    # Echo stuff to see what their results are
    echo $sql."<br>";
    echo $count."<br>";

    # Let's see if we all got it right?
     if($count==1){
    while ($row=mysql_fetch_array($query)) {
    $username=$row['un'];
    $heslo=$row['pw'];
    $_SESSION['valid'] = $username;
if(isset($_SESSION['valid'])){
        $realtime = date("d-m-Y h:i:s"); 
        $session = $_SESSION['valid'];
        # Commented out for testing purposes. I mean the header.
        echo "all is well";
        //header("Location: index.php");
} // this closes the if(isset... 
} // this closes the while loop
# Note that the curly brackets have changed. Now the else points correctly to the other branch if $count is not equal to 1.
}   else {
        echo "Přihlášení neproběhlo správně";
    }