Jump to content

strpos(), substing a little to sub


lewashby

Recommended Posts

In the following program the strpos() functions work for most cases are failing in one instance. If you type nothing, something completely random, or the email address and or password with any extra characters the program will not let the user through as they are unknown. The problem is that if you type a partial email address or password that's in the text file it's still substring of that line and is thus cleared as a known user. How can I better protect the process so that strpos() is checking $line for exact matches of email, & password? They are both on the same line separated with only white spaces.

<?php

session_start();

$_SESSION['email'] = $_POST['email'];
$_SESSION['psswd'] = $_POST['psswd'];

$db = new SQLite3('./users.db', SQLITE3_OPEN_READWRITE);
$file = fopen("./accounts.txt", 'r+') or die("Failed to open file");

while(!feof($file))
{
    $line = fgets($file);
    if(strpos($line, $_SESSION['email']) !== false)
    {
        if(strpos($line, $_SESSION['psswd']) !== false)
        {
        header("location: ./changepassword.html");
        break;
        }
    }
}
    echo "Unknown username and or password";        
    fclose($file);
?>

 

Link to comment
https://forums.phpfreaks.com/topic/282756-strpos-substing-a-little-to-sub/
Share on other sites

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.