mysql — проверка подтверждения пароля в переполнении стека

<?php
include("../../config/database_connection.php");

if( isset($_POST) )
{
$user_name   =$_POST['user_name'];
$email   = $_POST['email'];
$user_pass_init    = $_POST['password'];
$user_pass_conf = $_POST['passconfirm'];
$full_name = $_POST['full_name'];
$gender = $_POST['gender'];

if ($user_name!="" && $email!="" && $full_name!="" && $gender!="") {
if ($_POST['password']!= $_POST['passconfirm']) {
header("location:../index.php?err= password do not match");
}else{
$query   = "INSERT into admin_users (user_name,email,user_pass,full_name,gender) VALUES('" . $user_name . "','" . $email . "','" . md5($user_pass_init) . "','" . $full_name . "','" . $gender . "')";
$success = $conn->query($query);
}

if (!$success) {
die("Couldn't enter data: ".$conn->error);
} else{
header("location:../index.php");
}
} else{
header("location:../index.php?err= Enter all the fields");
}
} else{
header("location:../index.php?err= couldnot enter data");
}
?>

это код, который я пытаюсь выполнить, чтобы проверить, совпадают ли два пароля или нет … но при вводе одинаковых паролей я получаю значение пароля не совпадает
В чем проблема? Помоги мне решить это

0

Решение

Вот моя рекомендация, это может не полностью решить вашу проблему, но сделает ваш код немного более безопасным, поскольку ваш код подвержен SQL-инъекции:

<?php
include("../../config/database_connection.php");
if( isset($_POST) )
{
$user_name  = $conn->real_escape_string($_POST['user_name']);
$email   = $conn->real_escape_string($_POST['email']);
$user_pass_init    = $conn->real_escape_string($_POST['password']);
$user_pass_conf = $conn->real_escape_string($_POST['passconfirm']);
$full_name = $conn->real_escape_string($_POST['full_name']);
$gender = $conn->real_escape_string($_POST['gender']);

if (!empty($user_name) && !empty($email) && !empty($full_name) && !empty($gender)) {
if ($user_pass_init != $user_pass_conf) {
header("location:../index.php?err= password do not match");
}else{
$user_pass = md5($user_pass_init);
$query   = "INSERT into admin_users (user_name,email,user_pass,full_name,gender) VALUES('$user_name', '$email', '$user_pass', '$full_name', '$gender')";
$success = $conn->query($query);
if (!$success) {
die("Couldn't enter data: ".$conn->error);
} else{
header("location:../index.php");
}
}
} else{
header("location:../index.php?err= Enter all the fields");
}
} else{
header("location:../index.php?err= couldnot enter data");
}
?>

Я также рекомендовал бы использовать password_hash() вместо md5()

1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector