I guess so. In your script above you are doing the following:
$password = $_POST['password'];
$hmac = hash_hmac('sha512', $password, file_get_contents('textfiles/key.txt'));
And then you compare the given password to the one in the database as follows:
if(crypt($hmac, $hash) === $hash)
{
// Login info is correct.
}
Are you using the exact same way of encrypting the user's password when he registers? So is the encrypted password that is generated during the reigstration process the same as the encrypted password that is generated during the login process?