Jump to content

strpos(), substing a little to sub


lewashby
Go to solution Solved by vinny42,

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

  • Solution

 


 How can I better protect the process so that strpos() is checking $line for exact matches of email, & password? 

 

I'd split the lines from the file into separate vars for the email and the password, and simply compare without strpos().

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.