Page 1 of 1
User Authentication
Posted: Sun Oct 13, 2002 12:29 pm
by Xelmepa
Hey,
I am doing a user authentication script.
I am trying to see whether the given from a form username and password exist in any pair of a text file.
text file:
xelmepa::12345
nickp::54321
How can I see if the submitted username and password exist in one pair?
Posted: Sun Oct 13, 2002 12:37 pm
by twigletmac
One way could be to use
file() to read the text file into an array, then use
foreach() and
explode() to separate the username and password and
in_array() to check to see if the entered values exist as a pair.
Mac
Posted: Sun Oct 13, 2002 12:49 pm
by hob_goblin
Code: Select all
<?
$username = $_POSTї'username']; // user input
$password = $_POSTї'password']; // user input
$array = file('thetextfile.txt');
foreach($array as $value){
$temp = explode("::", $value);
if($username != $tempї'0'] || $password != $tempї'1']){
die('Invalid Username/Password');
}
}
// user is logged in
?>
Posted: Sun Oct 13, 2002 12:59 pm
by Xelmepa
I just did the following and the $_POST variables appear to be empty for some reason...
I used tabs (\t) instead of :: this time as a divider between username and pswd and newlines between sets of un and pwd.
Code: Select all
<?php
$user_name = $_POSTї'user_name'];
$password = $_POSTї'password'];
$fp = fopen("db.txt", "r");
while ($userinfo = fscanf ($fp, "%s\t%s\n")) {
list ($uname, $pwd) = $userinfo;
if (($user_name == $uname) && ($password == $pwd)) {
echo "succesful login!";
}
}
fclose($fp);
?>
[/quote]
Posted: Sun Oct 13, 2002 1:55 pm
by Xelmepa
Anyone got a clue why the $_POST array is empty?
I am using method=post
Posted: Sun Oct 13, 2002 2:18 pm
by Coco
are you aware of this ->
viewtopic.php?t=511
Posted: Sun Oct 13, 2002 3:33 pm
by hob_goblin
that has nothing to do with his question.
Xelmepa wrote:Anyone got a clue why the $_POST array is empty?
I am using method=post
Try $HTTP_POST_VARS
Posted: Mon Oct 14, 2002 1:54 am
by twigletmac
If you are using PHP 4.0.6 or below use $HTTP_POST_VARS (this array is also available on PHP > 4.0.6), if you are using PHP 4.1 or above $_POST should work.
Mac
Posted: Mon Oct 14, 2002 9:18 pm
by icesolid
If $_POST[""]; and $HTTP_POST_VARS[""]; are "empty" or will not work, then maybe there is something wrong in your PHP or server configuration?
Posted: Mon Oct 14, 2002 9:51 pm
by hob_goblin
Yes, such as 'track-vars' in php ini
Posted: Thu Oct 17, 2002 2:49 pm
by Xelmepa
Yea I figured after I asked it in here. Thanks though.
And yes I am aware of that topic pretty much, that's why I am using the POST vars
