I am having some issues with the PHP Crypt Function, which hopefully someone can help me out with.
I am designing a website for a sports club as a school project, and they don't want to pay for hosting that has a database. I therefore am having to make use of a Flat File DB which shall hold only a couple of passwords and the content created with the use of the CMS I am writing for them.
I currently have the following for my Login system:
<?php
session_start();
ini_set('display_errors', 1);
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$CurPassword = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/DB/Hash');
if(crypt($Password, $CurPassword) == $CurPassword){
echo("MATCH");
}
else{
echo("NO MATCH");
}
?>
The login system always returns "No Match", the Hash in the file is copied exactly with the use of the Crypt Function and therefore I don't understand what is going wrong. If I use
$CurPassword = crypt($Password);
instead it seems to work.I have only ever used a MySQL database, which I know is vulnerable to injection. Is a Flat File database like this still vulnerable, and how can I protect against it? At the moment, the only real security I have on the file is an HTAccess restriction and restricted file permissions.
In the past, I've been using a mix of Hashes and random salts to create a hash string. This is the first time I've used the crypt function, which one is better for password security, the Hash Function or the Crypt Function?
Thank you