Problema la autentificare

Ai o întrebare legată de PHP? Incercăm să îi găsim soluţie. Sau poate doar vrei să publici un cod interesant.

Moderatori: Zamolxe, Moderatori

Gabry
PHPRomania Supporter
Mesaje: 27
Membru din: Mar Apr 13, 2004 2:39 pm
Localitate: Bucuresti

Problema la autentificare

Mesajde Gabry » Mar Apr 13, 2004 3:36 pm

Primesc mereu urmatoarea eroare:"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result ..."
Nu inteleg unde gresesc, mai jos este codul sursa.

<?php
if (!isset ($_SERVER['PHP_AUTH_USER']))
{
header ('WWW-Authenticate:Basic realm="Test"');
header ('HTTP/1.0 401 Unauthorized');
echo 'Pentru accesarea acestei pagini este necesara o autentificare!';
exit;
}
else {
$linkID=mysql_connect("localhost","root","");
mysql_select_db("BD-Date",$linkID);
$result = mysql_query("SELECT User, Password FROM user WHERE User = \"" . $_SERVER['PHP_AUTH_USER'] . "\" AND Password = \"" . $_SERVER['PHP_AUTH_PW'] . "\"",$linkID);
while ($row=mysql_fetch_array($result))
{
if (($row['User'] == $_SERVER['PHP_AUTH_USER']) and ($row['Password'] == $_SERVER['PHP_AUTH_PW']))
{

echo "<html><head>";
echo "<title>Autentificare</title>";
echo "</head><body>";
echo "<p>Salut <b><i>{$_SERVER['PHP_AUTH_USER']}</ I></B>!";
echo "<p>Parola introdusa este <b><i>{$_SERVER['PHP_AUTH_PW']}</i></b>.";
echo "</body></html>";
}
else {
echo "<html><head>";
echo "<title>Autentificare</title>";
echo "</head><body>";
echo "<p>Parola introdusa este <b><i>gresita</i></b>.";
echo "</body></html>";

}
}
mysql_close($linkID);
}
?>

PS: Abia am inceput sa invat PHP asa ca va rog sa imi iertati nestiinta. :oops: :oops: :oops:
Oare sa fie din cauza password-ului care este criptat in BD? Sau pt ca nu exista o cheie primara unica?



Utopia
PHPRomania Supporter
Mesaje: 10
Membru din: Mie Apr 07, 2004 8:55 pm
Localitate: Bucuresti
Contact:

Mesajde Utopia » Mie Apr 14, 2004 7:21 pm

Pace si prosperitate!

Gabry
PHPRomania Supporter
Mesaje: 27
Membru din: Mar Apr 13, 2004 2:39 pm
Localitate: Bucuresti

Mesajde Gabry » Lun Mai 03, 2004 4:49 pm

Revin si pun iar in atentia voastra aceasta problema. Nu i-am dat de cap.

Am facut o noua tabela, users, de data asta, unde am user, password si password_cod(ificat). Totul merge f. bine daca folosesc user si password, insa, cand schimb password cu password_cod(ificat), apar problemele. Am verificat nu am nici o inregistrare in $result cand am password_cod(ificat). Am verificat si in mysql si tot 0 inregistrari am. Bunnnnnn, deci nu ii place de loc
$sql="SELECT user, password, password_cod FROM users WHERE user = \"" . $_SERVER['PHP_AUTH_USER'] . "\" AND password_cod = md5('" .$_SERVER['PHP_AUTH_PW']. "')";

Clar ca nu ii place password_cod=md5('')
Deci voi ce ziceti?

Multumesc,
Gabry

Zamolxe
Average Member
Mesaje: 130
Membru din: Mar Ian 14, 2003 4:50 pm
Localitate: Bucharest

re

Mesajde Zamolxe » Lun Mai 03, 2004 5:16 pm


Gabry
PHPRomania Supporter
Mesaje: 27
Membru din: Mar Apr 13, 2004 2:39 pm
Localitate: Bucuresti

Re: re

Mesajde Gabry » Lun Mai 03, 2004 5:33 pm

Nu mai primesc aceea eroare, am uitat sa specific ci pur si simplu am 0 inregistrari.

Uite codul php:

<?php
if (!isset ($_SERVER['PHP_AUTH_USER']))
{
header ('WWW-Authenticate:Basic realm="Nume"');
header ('HTTP/1.0 401 Unauthorized');
echo 'Pentru accesarea acestei pagini este necesara o autentificare!';
exit;
}
else {

// conectarea la bd si verificare

$linkID=mysql_connect("localhost","root","") or die("Nu m-am putut conecta la baza de date");
mysql_select_db("nume_db",$linkID) or die("Nu am putut selecta baza de date");


$sql="SELECT id_user_web, user_login, user_password, user_password_cod FROM users WHERE user_login = \"" . $_SERVER['PHP_AUTH_USER'] . "\" AND user_password_cod = \"" .md5($_SERVER['PHP_AUTH_PW']). "\"";

$result = mysql_query($sql,$linkID) or die(mysql_error());

$r=mysql_fetch_assoc($result);

$nr= mysql_num_rows($result);

if($nr==0)
{
echo"$nr\n";
exit;
}

while ($row=mysql_fetch_array($result))
{
if (($row['user_login'] == $_SERVER['PHP_AUTH_USER']) and ($row['user_password_cod'] == $_SERVER['PHP_AUTH_PW']))
{

echo "<html><head>";
echo "<title>Autentificare</title>";
echo "</head><body>";
echo "<p>Salut <b><i>{$_SERVER['PHP_AUTH_USER']}</ I></B>!";
echo "<p>Parola introdusa este <b><i>{$_SERVER['PHP_AUTH_PW']}</i></b>.";
echo "</body></html>";

}
else {
echo "<html><head>";
echo "<title>Autentificare</title>";
echo "</head><body>";
echo "<p>Parola introdusa este <b><i>gresita</i></b>.";
echo "</body></html>";

}
}
mysql_close($linkID);
}
?>

Zamolxe
Average Member
Mesaje: 130
Membru din: Mar Ian 14, 2003 4:50 pm
Localitate: Bucharest

re

Mesajde Zamolxe » Lun Mai 03, 2004 5:48 pm

pai atunci inseamna ca nu mai e nici o problema. introduce in baza de date un user si o parola cu md5 si totul este ok. mai sunt alte probleme?

serban

Gabry
PHPRomania Supporter
Mesaje: 27
Membru din: Mar Apr 13, 2004 2:39 pm
Localitate: Bucuresti

Re: re

Mesajde Gabry » Lun Mai 03, 2004 5:54 pm


Zamolxe
Average Member
Mesaje: 130
Membru din: Mar Ian 14, 2003 4:50 pm
Localitate: Bucharest

re

Mesajde Zamolxe » Lun Mai 03, 2004 6:24 pm


Gabry
PHPRomania Supporter
Mesaje: 27
Membru din: Mar Apr 13, 2004 2:39 pm
Localitate: Bucuresti

Mesajde Gabry » Mar Mai 04, 2004 4:45 pm



Înapoi la “Cod PHP”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 16 vizitatori