PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Tue Nov 25, 2003 10:39 pm
i'm working on a login script.
Code: Select all
<?php
$loginusername = $_POST['user'];
$loginpassword = md5($_POST['password']);
$registerednameandpass = $loginusername.$loginpassword;
//I want to search the user text file for a string($registerednameandpass), i'm not sure if i have to define the entire file as a str and search that or what
//I'm just not sure how to do it
if (if search returns true(the user and pass are found) there will be a cookie set)
else{
echo "Sorry you were not found in the database, please register";
}
?>
when a user registers his/her username and password are stuck together and written to a txt file
Code: Select all
($_POST['username']).(md5($_POST['password']))
in the end i want to be able to take the login info, make a string in a similar way to which i did in my register script, and then take that string and search the txt file for it so I can verify if the given person is a resistered user or not.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Nov 26, 2003 5:45 am
Code: Select all
$passwd_file=file($filename);
$loginusername = $_POST['user'];
$loginpassword = md5($_POST['password']);
$registerednameandpass = ($loginusername).(md5($loginpassword));
$login_ok=false;
foreach($passwd_file as $line)
if($registerednameandpass==$line)
$login_ok=true;
?
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Wed Nov 26, 2003 8:40 am
I tried that and no matter what the user and passwords (even if the given user and pass are not yet registered) it always returns login ok
Code: Select all
<?php
$passwd_file=file("include/userandpass.txt");
$loginusername = $_POST['user'];
$loginpassword = md5($_POST['password']);
$registerednameandpass = ($loginusername).(md5($loginpassword));
$login_ok = false;
foreach ($passwd_file as $line)
if ($registerednameandpass == $line)
$login_ok = true;
if ($login_ok = true)
echo "Login ok!";
else{
echo "Sorry you were not found in the database, please register";
}
?>
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Nov 26, 2003 9:15 am
The problem is here
= is
assignment operator. To compare values use
== operator.
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Wed Nov 26, 2003 9:59 am
ok, the compare statement works now, but it can't find my username and password in the txt file, even though i know it's in the txt file and is correct
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Wed Nov 26, 2003 10:02 am
heres my code now
login.php
Code: Select all
<?php
$passwd_file=file("include/userandpass.txt");
$loginusername = $_POST['user'];
$loginpassword = md5($_POST['password']);
$registerednameandpass = ($loginusername).(md5($loginpassword));
$login_ok = false;
foreach ($passwd_file as $line)
if ($registerednameandpass == $line)
$login_ok = true;
if ($login_ok == true){
echo "Login ok!";
}
else{
echo "Sorry you were not found in the database, please register";
}
?>
userandpass.txt
Code: Select all
dull1554d914e3ecf6cc481114a3f534a5faf90b
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Wed Nov 26, 2003 10:54 am
BUMP!
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Nov 26, 2003 10:58 am
oops... forgot to remove \ns.
Code: Select all
foreach ($passwd_file as $line)
if ($registerednameandpass == trim($line))
$login_ok = true;
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Wed Nov 26, 2003 10:59 am
try changing this
Code: Select all
if ($registerednameandpass == $line)
to...
Code: Select all
if ($registerednameandpass == chop($line))
Mark
Last edited by
JayBird on Wed Nov 26, 2003 11:14 am, edited 1 time in total.
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Wed Nov 26, 2003 11:10 am
neither helped, it still returns
Sorry you were not found in the database, please register
heres my code again
Code: Select all
<?php
$passwd_file=file("include/userandpass.txt");
$loginusername = $_POST['user'];
$loginpassword = md5($_POST['password']);
$registerednameandpass = ($loginusername).(md5($loginpassword));
$login_ok = false;
foreach ($passwd_file as $line)
if (chop($registerednameandpass) == $line)
$login_ok = true;
if ($login_ok == true){
echo "Login ok!";
}
else{
echo "Sorry you were not found in the database, please register";
}
?>
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Wed Nov 26, 2003 11:13 am
actually
i got mine the wrong way roung shoudl have been
Code: Select all
if ($registerednameandpass == chop($line))
chop is just an alias of rtrim (trim), so if weirdans didn't work, neither will chop
Mark
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Wed Nov 26, 2003 11:20 am
maybe i'll just scrap the whole script and start over, i just wanted to beable to make my usere login before they were able to download something, but i dont have a database at my disposal otherwise it would be a piece of cake. I really appreciate all the help!