Re: problem using &&

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



php@xxxxxxxxx wrote:
> 
> 
> On Wed, 26 Jul 2006 14:53:34 +0200, Jochem Maas <jochem@xxxxxxxxxxxxx> wrote:
>> php@xxxxxxxxx wrote:
>>> On Wed, 26 Jul 2006 13:54:15 +0200, Jochem Maas <jochem@xxxxxxxxxxxxx>
>> wrote:
>>>> var_dump($out, $u, $p, (" user " == "user"));
>>> Jochem
>>> Thank you, var_dump showed me i had an extra space at the end of the
>> password. I trimmed the vales from the file and it works fine now.
>>
>> LOL - that's one lesson/trick you probably won't forget in a hurry...
>> most of us have had similar experiences at one time or the other!
> 
> I sure wont.
> On the topic of my array, what would be an efficient way of checking my username/passwordd pairs match the user input form my login form.
> The text file contains username and passwords in the following format:
> username1,password1
> username2,password2

I dunno, something like this maybe:

$u = trim($_POST['usr']);
$p = trim($_POST['pwd']);

$lines = file('/you/pwd/file');
$users = array();
foreach ($lines as $line) {
	list($usr, $pwd) = explode(',',$line);
	$users[ $usr ] = $pwd;
}

if (isset($users[ $u ]) && ($users[ $u ] === $p)) {
	echo "Found {$u}, and password is correct.";
}

> Given I have only 2 its easy to do this in one if statement testing like so:
> if( ($out[0][0]) == ($u) && ($out[0][1]) == ($p) || $out[1][0] == $u && $out[1][1] == $p )
> But if I had more or n amount, what would be an efficient way to check the pairs?
> Thanks
> Eoghan
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux