0

hi there i'm using a text file as a database the contents of my text file are as follows....

SRC ---> M ---> 11/22/1995 ---> myPassword ---> 11/29/2013

what i want to do is write a php code that searches for src and returns the password i am using the following code to search the text file..

<?php
$file = 'Database.txt';
$searchfor = 'src';

// the following line prevents the browser from parsing this as HTML.
header('Content-Type: text/plain');

// get the file contents, assuming the file to be readable (and exist)
$contents = file_get_contents($file);
// escape special characters in the query
$pattern = preg_quote($searchfor, '/');
// finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/m";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
   echo implode("\n", $matches[0]);
}
else{
   echo "No matches found";
}
?>

how can i make it echo the password.... any help would be appreciated... thanks in advance... :) i know using text file as a database isn't secure but still...

15
  • 4
    "how can i make it echo the password" – Believe me, you don't want to do that. Commented Nov 29, 2013 at 16:24
  • 2
    Never ever ever ever store a password as plaintext. And what Fred said… I hope that's not your real email address in the code. You need to become a little more paranoid if you are going to connect your computer to the internet. Commented Nov 29, 2013 at 16:25
  • haha.... i know..... well... it's not gonna echo the password.... it's gonna do other things.... all i need is it to get the password... sooo i said echo. Commented Nov 29, 2013 at 16:25
  • @Floris: it was. not anymore, luckily. Commented Nov 29, 2013 at 16:26
  • 2
    Just to clarify what others have been saying: If you're working with passwords they should never be stored as plain text, even if it's in your database and never shown on screen. The best way to handle passwords is to use a hashing algorithm such as bcrypt immediately when it is first input. Then any subsequent password checks should hash their input and compare the hashes. The original password should kept be in state that even the system administrator cannot recover it. If not, your system is not secure: there have been many cases of hackers publishing password data: don't be one of them Commented Nov 29, 2013 at 16:34

1 Answer 1

0

i just put in this code:

$strArray = explode(' ---> ',implode($matches[0]));
$name = $strArray[3];
echo "\n" . $name;

after:

if(preg_match_all($pattern, $contents, $matches)){

tho i took a bit of a help from PHP - get certain word from string

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.