mbrown174 wrote:Hello, Im trying to create a one page password script that uses a text file for password storage.
To do this is extremely UN-secure. I urge you not to store passwords in a text file, as text files are readable from a browser, and if someone finds it, they will have keys to the castle... At the very least ENCRYPT your password using sha1() or md5() functions for example ....
To look at your example, however, it appears that you are trying to access the variable $Password without assigning the POSTED value to the variable. So, try:
if(isset($_POST['Password'])) { $Password = trim($_POST['Password']); }
OR, use the POST super global directly:
if ($_POST['Password'] == 'admin')
Next, you are not reading the value FROM your password text file at all. You are using the hard-coded value for your password: "admin"
So, what do you need the text file for if you are doing this??
Putting it together, I would try this:
<?php
// if POST
if (isset($_POST['Password']))
{
if($_POST['Password'] == 'admin')
{
echo "Well Done!";
} else {
echo "Nope not correct";
}
}
// display form:
else {
?>
<form action="<?php htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES); ?>" method="POST">
Enter your password: <input type="password" name="Password" />
<input type="submit" />
<?php } ?>
Lastly, there is an HTML form element called input type: "password"
Use that for the input type rather than "text" for your passwords.