Answer the question
In order to leave comments, you need to log in
php. Authorization doesn't work. Where is the mistake?
Hello. Guys, there was a problem. I'm doing authorization here, I wrote the code, but it doesn't work.
MySql DB structure:
Table 'users'
username || email || password
Here is the code:
if($_POST['username'] == "")
echo 'Введите логин.';
else
$username = $_POST['username'];
if($_POST['password'] == "")
echo 'Введите пароль';
else
$hashpassword = password_hash($_POST['password'], PASSWORD_DEFAULT);
if(isset($username) && isset($hashpassword))
{
$q1 = mysql_query("SELECT * FROM users WHERE username='".$username."'");
if(mysql_num_rows($q1) == 1)
{
$password_by_username = mysql_query("SELECT password FROM users WHERE username = '".$username"'");
if($hashpassword == $password_by_username)
echo 'Вы успешно авторизовались!';
else
echo 'Вы ввели неверный пароль';
}
else
echo 'Вы ввели неверный логин.';
}
Answer the question
In order to leave comments, you need to log in
1. isset($password)
$password - what kind of variable is this? In the code, you only have $_POST['password'] and $hashpassword.
This is where the condition doesn't work.
2.
$password_by_username = mysql_query("SELECT password FROM users WHERE username = '".$username"'");
1) I'm embarrassed to ask - is there a connection to the database?
2) How is the output of errors configured in php?
3) if the output is not configured - most likely errors are not displayed, but the code falls on error.
4) The code is just hellish hell, also with light injection.
5)
$q1 = mysql_query("
SELECT *
FROM users
WHERE `username`= $username
and `password = $hashpassword
");
if(mysql_num_rows($q1) == 1) echo "ура, залогинились!"
else "блиин, неверные данные авторизации";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question