User Authentication
Moderator: General Moderators
User Authentication
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?
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?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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
Mac
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
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
?>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.[/quote]
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);
?>are you aware of this -> viewtopic.php?t=511
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
that has nothing to do with his question.Coco wrote:are you aware of this -> viewtopic.php?t=511
Try $HTTP_POST_VARSXelmepa wrote:Anyone got a clue why the $_POST array is empty?
I am using method=post
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact: