Jump to content

Help with user/pass verification


chaosxkitten

Recommended Posts

I know there has to be a better way to do this. My usernames and passwords are stored in a text file. This is what I'm doing now, and all it does is return the error statement.

 

This is the php from after the log in page.

<?php

$user = $_POST["username"];
$password = $_POST["password"];

$un = "no";
$pw = "no";

$fh = fopen("users.txt","r");

while (!feof($fh)) { 
     $line =  fgets($fh);
     $data = explode("$",$line);
     if ($data["0"] == $user){
 $un = "yes";
     }
     if ($data["1"] == $password){
 $pw = "yes";
     }	     
}

if (($un === "yes") &&  ($pw === "yes")){
    
    echo "<h4> Hello <em>$user</em>!\n<br />";

}else {

echo "<h3>Your username and/or password is incorrect.</h3>\n<br />";
echo "<a href='login.html'>Return to the login page.</a>\n<br />";

}

fclose($fh);

?>

 

Link to comment
Share on other sites

can't really help without showing us example of what your users.txt file looks like (the format of the contents) but anyways, this is a terrible way of doing a login system.  For starters, what prevents a user from being able to go directly to www.yoursite.com/users.txt and getting everybody's login info? You should be storing this information in a database.  2nd, you should be encrypting the password (which based on your posted code, you aren't).  There are a million login/authentication tutorials out there, I suggest you scrap this, pick one and follow it.

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.