/    Sign up×
Community /Pin to ProfileBookmark

How: Compare entered PW to a PW data file

Uggh!!!!
I may be going about this all wrong.
My goal is to write a password protection script.
I’m a newbie to PHP, so be gentile.
I’ve written the file successfully,
now I’m trying to read from the file, however, I’m not sure how to compare the entered username (UN) & password (PW) with the UN/PW in the data file.
I can get the data to display with the following script, however,
I’m feeling kinda lost, disoriented, and a little green around the gills.

Can anyone help, or should I just drink the Koolaid?


____________________________________________________________

<?php
function ReadFromFile () {
$TheFile = “wmdata.txt”;
$Open = fopen ($TheFile, “r”);
if ($Open) {
print (“Data currently listed in the data file:<P>n”);
$Data = file ($TheFile);
for ($n = 0; $n < count($Data); $n++) {
$GetLine = explode(“t”, $Data[$n]);
print (“$GetLine[0]<BR>n$GetLine[1]<P>n”);
}
fclose ($Open);
print (“<HR><P>n”);
} else {
print (“Unable to read from data.txt!<BR>n”);
}
}
?>

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 05.2005 — You might do something like this:
[code=php]
<?php
function check_login($name, $password)
{
$TheFile = "wmdata.txt";
$Data = file($TheFile) or die("Unable to read user data file.");
foreach($Data as $line)
{
$GetLine = explode("t", rtrim($line));
if($GetLine[0] == $name and $GetLine[1] == $password)
{
return(TRUE); # found it
}
}
return(FALSE);
}
### sample use, assumes login form has fields "login" and "password":
if(check_login($_POST['login'], $_POST['password']))
{
# valid login, so procede as desired
}
else
{
# invalid login, so display error message or other error handling process
}
?>
[/code]
×

Success!

Help @BrindeeLee spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...