session_start();
$conn_db = mysqli_connect("localhost","root","","practice");
$fsmsg = "Старый пароль не подходит!";
$username = $_POST['username'];
$email = $_POST['email'];
$old_password = $_POST['old_password'];
$new_password = $_POST['new_password'];
$msg = "Ваш новый пароль: $new_password";
$password = $_POST['password'];
$new_username = $_POST['new_username'];
$hash = password_hash($password, PASSWORD_DEFAULT);
// Если кнопка апдейт нажата, изменить значения полей
if (isset($_POST['update'])) {
if (isHashVerify($username, $old_password, $conn_db)) {
$newHash = password_hash($new_password, PASSWORD_DEFAULT);
$update2 = "UPDATE `users` SET `password`='$newHash' WHERE `username`='$username'";
$resultupdate = mysqli_query($conn_db, $update2) or die (mysqli_error($conn_db));
echo("<br><h2>{$msg}</h2>\n");
} else {
echo("<br><h2>{$fsmsg}</h2>\n");
}
}
function isHashVerify($username, $oldPassword, $db) {
$query = "SELECT `password` FROM `users` WHERE `username`='$username'";
$currentPassword = mysqli_query($db, $query)->fetch_assoc() or die (mysqli_error($db));
return password_verify($oldPassword, $currentPassword["password"]);
}
<button class="demo btn-danger">Демо расчёт</button>
$('.demo').click(function() {
let
D_fl_text = $('input[name="D_fl"]'),
D_fl_text.val(175);
})
<?php
session_start();
require('connect.php');
if (isset($_POST['username']) and isset ($_POST['password'])){
$hash = password_hash($password, PASSWORD_DEFAULT);
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$role = $_POST['role'];
$query = 'INSERT INTO users SET username="'.$username.'", email="'.$email.'", password="'.password_hash($password, PASSWORD_DEFAULT).'", role="user"';
$result = mysqli_query($connection, $query);
if ($result){
header('Location: index.html');
$smsg = "Регистрация прошла успешно";
} else {
$fsmsg = "Ошибка";
}
}
$hash = password_hash('12345', PASSWORD_DEFAULT);
if (password_verify('12345', $hash)) {