{"id":333083,"date":"2022-05-13T15:00:24","date_gmt":"2022-05-13T15:00:24","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=333083"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=333083","title":{"rendered":"<span>\u041f\u0440\u043e\u0441\u0442\u0430\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043d\u0430 PHP<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 \u043d\u043e\u0432\u0438\u0447\u043a\u0438 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 \u0442\u0443\u043f\u0438\u043a \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 PHP. \u041d\u0430 \u0422\u043e\u0441\u0442\u0435\u0440\u0435 \u0441 \u0437\u0430\u0432\u0438\u0434\u043d\u043e\u0439 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u043f\u0430\u0440\u043e\u043b\u044c \u0441 \u043f\u0430\u0440\u043e\u043b\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0438\u0437 \u0444\u043e\u0440\u043c\u044b \u043b\u043e\u0433\u0438\u043d\u0430. \u0417\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u043a\u0440\u0430\u0442\u043a\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f-\u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443.<\/p>\n<p><strong>Disclaimer:<\/strong> \u0441\u0442\u0430\u0442\u044c\u044f \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u0430 \u043d\u0430 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u044b\u0445 \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432. \u0423\u043c\u0443\u0434\u0440\u0451\u043d\u043d\u044b\u0435 \u043e\u043f\u044b\u0442\u043e\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u043d\u0430\u0439\u0434\u0443\u0442, \u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043d\u0435\u0434\u043e\u0447\u0451\u0442\u044b =).<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 MySQL\/MariaDB, PHP, <a href=\"https:\/\/www.php.net\/manual\/ru\/book.pdo.php\" rel=\"noopener noreferrer nofollow\">PDO<\/a>, <a href=\"https:\/\/www.php.net\/manual\/ru\/ref.password.php\" rel=\"noopener noreferrer nofollow\">\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0430\u0440\u043e\u043b\u044f\u043c\u0438<\/a>, \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0432\u043e\u0437\u044c\u043c\u0451\u043c <a href=\"https:\/\/getbootstrap.com\/\" rel=\"noopener noreferrer nofollow\">bootstrap<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u0430\u0437\u0443. \u041f\u0443\u0441\u0442\u044c \u043e\u043d\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f php-auth-demo. \u0412 \u043d\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 <code>users<\/code>:<\/p>\n<pre><code class=\"sql\">CREATE TABLE `users` (     `id` int unsigned NOT NULL AUTO_INCREMENT,     `username` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,     `password` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,     PRIMARY KEY (`id`),     UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043d\u0444\u0438\u0433 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435.<\/p>\n<p><em>\u0418\u043c\u0435\u0439\u0442\u0435 \u0432\u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043a \u043a\u043e\u043d\u0444\u0438\u0433\u0430\u043c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430, \u0438 \u043e\u043d\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0432\u0435\u0440\u0441\u0438\u0439, \u0432\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u0440\u043e\u043c\u0435\u0442\u0430\u0446\u0438\u0438 \u0443\u0447\u0435\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/em><\/p>\n<p><code>config.php<\/code><\/p>\n<pre><code class=\"php\">&lt;?php  return [     'db_name' => 'php-auth-demo',     'db_host' => '127.0.0.1',     'db_user' => 'mysql',     'db_pass' => 'mysql', ];<\/code><\/pre>\n<p>\u0418 \u0441\u0434\u0435\u043b\u0430\u0435\u043c &#171;\u0437\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u044b\u0439&#187; \u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<p><em>\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. \u041d\u043e \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u0441\u0442\u0430\u0442\u044c\u0438, \u0438 \u0432 \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u043e\u0431\u043e\u0439\u0434\u0451\u043c\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c.<\/em><\/p>\n<p>\u0412 &#171;\u0437\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u043c&#187; \u0444\u0430\u0439\u043b\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u044e \u0438 \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0438. <\/p>\n<p><code>boot.php<\/code><\/p>\n<pre><code class=\"php\">&lt;?php  \/\/ \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u0435\u0441\u0441\u0438\u044e session_start();  \/\/ \u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432 \u0411\u0414 function pdo(): PDO {     static $pdo;      if (!$pdo) {         $config = include __DIR__.'\/config.php';         \/\/ \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0411\u0414         $dsn = 'mysql:dbname='.$config['db_name'].';host='.$config['db_host'];         $pdo = new PDO($dsn, $config['db_user'], $config['db_pass']);         $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);     }      return $pdo; }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>pdo()<\/code> \u0434\u0430\u0441\u0442 \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443 PDO \u0432 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0444\u043e\u0440\u043c\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438. \u0420\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u0435\u0451 \u043f\u0440\u044f\u043c\u043e \u0432 \u0444\u0430\u0439\u043b\u0435 <code>index.php<\/code>.<\/p>\n<pre><code class=\"xml\">&lt;form method=\"post\" action=\"do_register.php\">   &lt;div class=\"mb-3\">     &lt;label for=\"username\" class=\"form-label\">Username&lt;\/label>     &lt;input type=\"text\" class=\"form-control\" id=\"username\" name=\"username\" required>   &lt;\/div>   &lt;div class=\"mb-3\">     &lt;label for=\"password\" class=\"form-label\">Password&lt;\/label>     &lt;input type=\"password\" class=\"form-control\" id=\"password\" name=\"password\" required>   &lt;\/div>   &lt;button type=\"submit\" class=\"btn btn-primary\">Register&lt;\/button> &lt;\/form><\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e: \u0434\u0432\u0430 \u043f\u043e\u043b\u044f, \u043a\u043d\u043e\u043f\u043a\u0430 \u0438 \u0444\u043e\u0440\u043c\u0430, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0444\u0430\u0439\u043b <code>do_register.php<\/code> \u043c\u0435\u0442\u043e\u0434\u043e\u043c POST. \u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u043f\u0438\u0448\u0435\u043c \u0432 \u0444\u0430\u0439\u043b\u0435 <code>do_register.php<\/code>.<\/p>\n<pre><code class=\"php\">&lt;?php  require_once __DIR__.'\/boot.php';  \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u043d\u0435 \u0437\u0430\u043d\u044f\u0442\u043e \u043b\u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f $stmt = pdo()->prepare(\"SELECT * FROM `users` WHERE `username` = :username\"); $stmt->execute(['username' => $_POST['username']]); if ($stmt->rowCount() > 0) {     flash('\u042d\u0442\u043e \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0443\u0436\u0435 \u0437\u0430\u043d\u044f\u0442\u043e.');     header('Location: \/'); \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0442 \u043d\u0430 \u0444\u043e\u0440\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438     die; \/\/ \u041e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u0430 }  \/\/ \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0431\u0430\u0437\u0443 $stmt = pdo()->prepare(\"INSERT INTO `users` (`username`, `password`) VALUES (:username, :password)\"); $stmt->execute([     'username' => $_POST['username'],     'password' => password_hash($_POST['password'], PASSWORD_DEFAULT), ]);  header('Location: login.php');<\/code><\/pre>\n<p>\u0412 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u043d\u0430\u0448 &#171;\u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a&#187;.<\/p>\n<p>\u041f\u043e\u0442\u043e\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u043d\u0435 \u0437\u0430\u043d\u044f\u0442\u043e \u043b\u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0443\u043a\u0430\u0437\u0430\u0432 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0438\u0437 \u0444\u043e\u0440\u043c\u044b \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0437\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/www.php.net\/manual\/ru\/pdo.prepared-statements.php\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/a>, \u0447\u0442\u043e \u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u0438\u0442 \u043d\u0430\u0441 \u043e\u0442 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%92%D0%BD%D0%B5%D0%B4%D1%80%D0%B5%D0%BD%D0%B8%D0%B5_SQL-%D0%BA%D0%BE%D0%B4%D0%B0\" rel=\"noopener noreferrer nofollow\">SQL-\u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0439<\/a>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u044b, \u0430 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u0443\u0435\u043c \u0441 \u043d\u0438\u043c\u0438 \u043d\u0435\u043d\u0430\u0434\u0451\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u043d\u0435\u043d\u0430\u0434\u0451\u0436\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u0432\u043d\u0435 \u2013 $_GET, $_POST, $_REQUEST, $_COOCKIE). \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0451\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a. \u0415\u0441\u043b\u0438 \u0438\u0445 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f, \u0442\u043e \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0443\u0436\u0435 \u0437\u0430\u043d\u044f\u0442\u043e. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438 \u0432\u0435\u0440\u043d\u0451\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0444\u043e\u0440\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p><em>\u042f \u043d\u0430\u043f\u0438\u0441\u0430\u043b &#171;\u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f&#187;, \u043d\u043e \u043f\u043e \u0444\u0430\u043a\u0442\u0443, \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u043e\u043b\u0435 <\/em><code>username<\/code><em> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435, <\/em><code>rowCount()<\/code><em> \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043b\u0438\u0448\u044c \u0434\u0432\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f: <\/em><code>0<\/code><em> \u0438 <\/em><code>1<\/code><em>.<\/em><\/p>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043a\u043e\u0434\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>flash()<\/code>. \u0414\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f &#171;\u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u044b\u0445&#187; \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0415\u0441\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0435\u0451 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c, \u0442\u043e \u043e\u043d\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u0441\u0435\u0441\u0441\u0438\u0438, \u0430 \u0435\u0441\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0442\u043e \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u0438\u0437 \u0441\u0435\u0441\u0441\u0438\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u0442\u0435\u043c \u0443\u0434\u0430\u043b\u0438\u0442 \u0435\u0433\u043e \u0432 \u0441\u0435\u0441\u0441\u0438\u0438. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u0444\u0430\u0439\u043b <code>boot.php<\/code>.<\/p>\n<pre><code class=\"php\">function flash(?string $message = null) {     if ($message) {         $_SESSION['flash'] = $message;     } else {         if ($_SESSION['flash']) { ?>           &lt;div class=\"alert alert-danger mb-3\">               &lt;?=$_SESSION['flash']?>           &lt;\/div>         &lt;?php }         unset($_SESSION['flash']);     } }<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u0435\u0451 \u043da \u0444\u043e\u0440\u043c\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"xml\">&lt;h1 class=\"mb-5\">Registration&lt;\/h1>  &lt;?php flash(); ?>  &lt;form method=\"post\" action=\"do_register.php\">     &lt;!-- ... --> &lt;\/form><\/code><\/pre>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0433\u043e\u0442\u043e\u0432.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043e\u0434 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u0448\u0435, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u043c\u044b \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043b\u043e\u0433\u0438\u043d\u0430. \u0421\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0435\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c.<\/p>\n<p><code>login.php<\/code><\/p>\n<pre><code class=\"xml\">&lt;h1 class=\"mb-5\">Login&lt;\/h1>  &lt;?php flash() ?>  &lt;form method=\"post\" action=\"do_login.php\">     &lt;div class=\"mb-3\">         &lt;label for=\"username\" class=\"form-label\">Username&lt;\/label>         &lt;input type=\"text\" class=\"form-control\" id=\"username\" name=\"username\" required>     &lt;\/div>     &lt;div class=\"mb-3\">         &lt;label for=\"password\" class=\"form-label\">Password&lt;\/label>         &lt;input type=\"password\" class=\"form-control\" id=\"password\" name=\"password\" required>     &lt;\/div>     &lt;div class=\"d-flex justify-content-between\">         &lt;button type=\"submit\" class=\"btn btn-primary\">Login&lt;\/button>         &lt;a class=\"btn btn-outline-primary\" href=\"index.php\">Register&lt;\/a>     &lt;\/div> &lt;\/form><\/code><\/pre>\n<p>\u0412 \u0432\u0438\u0434\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043e\u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442 \u0444\u043e\u0440\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043b\u043e\u0433\u0438\u043d\u0430 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>do_login.php<\/code>.<\/p>\n<p><code>do_login.php<\/code><\/p>\n<pre><code>&lt;?php  require_once __DIR__.'\/boot.php';  \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u044e\u0437\u0435\u0440\u043d\u0435\u0439\u043c\u043e\u043c $stmt = pdo()->prepare(\"SELECT * FROM `users` WHERE `username` = :username\"); $stmt->execute(['username' => $_POST['username']]); if (!$stmt->rowCount()) {     flash('\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d');     header('Location: login.php');     die; } $user = $stmt->fetch(PDO::FETCH_ASSOC);  \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043f\u0430\u0440\u043e\u043b\u044c if (password_verify($_POST['password'], $user['password'])) {     \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043d\u043e\u0432\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c     \/\/ \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c     \/\/ \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442\u0435 \u043e\u043f\u0446\u0438\u0438 \u0445\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f     if (password_needs_rehash($user['password'], PASSWORD_DEFAULT)) {         $newHash = password_hash($_POST['password'], PASSWORD_DEFAULT);         $stmt = pdo()->prepare('UPDATE `users` SET `password` = :password WHERE `username` = :username');         $stmt->execute([             'username' => $_POST['username'],             'password' => $newHash,         ]);     }     $_SESSION['user_id'] = $user['id'];     header('Location: \/');     die; }  flash('\u041f\u0430\u0440\u043e\u043b\u044c \u043d\u0435\u0432\u0435\u0440\u0435\u043d'); header('Location: login.php');<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0432\u0430\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u041c\u044b \u043d\u0435 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u043e \u043f\u0430\u0440\u0435 <em>username\/password<\/em>, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e <em>username<\/em>. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0445\u0435\u0448\u0438\u0440\u0443\u0435\u0442\u0435 \u043f\u0440\u0438\u0448\u0435\u0434\u0448\u0438\u0439 \u0438\u0437 \u0444\u043e\u0440\u043c\u044b \u043b\u043e\u0433\u0438\u043d\u0430 \u043f\u0430\u0440\u043e\u043b\u044c \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u0442\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0445\u0435\u0448 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u043c \u0432 \u0431\u0430\u0437\u0435, \u0432\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435. <code>Password_hash()<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0441\u043e\u043b\u044c \u0434\u043b\u044f \u043f\u0430\u0440\u043e\u043b\u0435\u0439 \u0438 \u0445\u0435\u0448\u0438 \u0431\u0443\u0434\u0443\u0442 <em>\u0432\u0441\u0435\u0433\u0434\u0430<\/em> \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u0437\u043d\u044b\u0435. \u0412\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>password_hash<\/code>, \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u043e\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437  \u0434\u043b\u044f \u043f\u0430\u0440\u043e\u043b\u044f &#171;123&#187;:<\/p>\n<pre><code>$2y$10$loqucup11.3DL1fgDWanoettFpFJuFFd0fY6BZyiP698ZqvA4tmuy $2y$10$.LF3OzmQRtJvuZZWeWF.2u80x3ls6OEAU5J9gLHDtcYrFzJkRRPvq $2y$10$iGj\/nOCavShd2vbMZTC4GOMYCqDj2YSc8qWoeqjVbD1xaKU2CgAfi<\/code><\/pre>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>password_verify<\/code> \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0430\u0440\u043e\u043b\u044f. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0434\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0434\u043b\u044f <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%90%D1%82%D0%B0%D0%BA%D0%B0_%D0%BF%D0%BE_%D0%B2%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%B8\" rel=\"noopener noreferrer nofollow\">\u0430\u0442\u0430\u043a \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/a>.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043f\u0430\u0440\u043e\u043b\u044c \u043d\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0445\u0435\u0448\u0430, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0432\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0445\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u0435\u0433\u043e \u043e\u043f\u0446\u0438\u0438.<\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u043b\u043e\u0433\u0438\u043d\u0430 \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0441\u0435\u0441\u0441\u0438\u0438, \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u043e\u0433\u043e \u0444\u0430\u043a\u0442\u0430, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0435\u043d, \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0432 \u0441\u0435\u0441\u0441\u0438\u0438. \u041c\u044b \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u0438 \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u0435\u0435 \u0432 \u0442\u043e\u043c \u0436\u0435 \u0444\u0430\u0439\u043b\u0435 <code>boot.php<\/code>.<\/p>\n<pre><code class=\"php\">function check_auth(): bool {     return !!($_SESSION['user_id'] ?? false); }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d.<\/p>\n<pre><code class=\"xml\">&lt;?php require_once __DIR__.'\/boot.php';  $user = null;  if (check_auth()) {     \/\/ \u041f\u043e\u043b\u0443\u0447\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u043c\u0443 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443     $stmt = pdo()->prepare(\"SELECT * FROM `users` WHERE `id` = :id\");     $stmt->execute(['id' => $_SESSION['user_id']]);     $user = $stmt->fetch(PDO::FETCH_ASSOC); } ?> &lt;?php if ($user) { ?>      &lt;h1>Welcome back, &lt;?=$user['username']?>!&lt;\/h1>      &lt;form class=\"mt-5\" method=\"post\" action=\"do_logout.php\">         &lt;button type=\"submit\" class=\"btn btn-primary\">Logout&lt;\/button>     &lt;\/form>  &lt;?php } else { ?>      &lt;h1 class=\"mb-5\">Registration&lt;\/h1>      &lt;?php flash(); ?>      &lt;form method=\"post\" action=\"do_register.php\">         &lt;!-- ... -->     &lt;\/form>  &lt;?php } ?><\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0444\u043e\u0440\u043c\u0435 \u043b\u043e\u0433\u0438\u043d\u0430, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u0436\u0435 \u0432\u043e\u0448\u0451\u043b:<\/p>\n<p><code>login.php<\/code><\/p>\n<pre><code class=\"php\">&lt;?php  require_once __DIR__.'\/boot.php';  if (check_auth()) {     header('Location: \/');     die; } ?> &lt;!-- \u0414\u0430\u043b\u0435\u0435 \u0444\u043e\u0440\u043c\u0430 \u043b\u043e\u0433\u0438\u043d\u0430 --><\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c &#171;\u0432\u044b\u0439\u0442\u0438&#187;. \u0424\u043e\u0440\u043c\u0443 \u0434\u043b\u044f \u0432\u044b\u0445\u043e\u0434\u044b \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435. \u0421\u0430\u043c\u0430 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0432\u044b\u0445\u043e\u0434\u0430 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f, \u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0447\u0438\u0441\u0442\u043a\u0435 \u0441\u0435\u0441\u0441\u0438\u0438.<\/p>\n<pre><code class=\"php\">&lt;?php  require_once __DIR__.'\/boot.php';  $_SESSION['user_id'] = null; header('Location: \/');<\/code><\/pre>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0418\u0442\u043e\u0433\u043e:<\/p>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/www.php.net\/manual\/ru\/book.pdo.php\" rel=\"noopener noreferrer nofollow\">PDO<\/a>\/<a href=\"https:\/\/www.php.net\/manual\/ru\/book.mysqli.php\" rel=\"noopener noreferrer nofollow\">MySQLi<\/a> \u0438 <a href=\"https:\/\/www.php.net\/manual\/ru\/pdo.prepared-statements.php\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/a> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0445\u0435\u0448 \u043f\u0430\u0440\u043e\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0445\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u0440\u043e\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <a href=\"https:\/\/www.php.net\/manual\/ru\/function.password-hash.php\" rel=\"noopener noreferrer nofollow\">password_hash<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0430\u0440\u043e\u043b\u044f \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0445\u0435\u0448\u0435\u0439, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <a href=\"https:\/\/www.php.net\/manual\/ru\/function.password-verify.php\" rel=\"noopener noreferrer nofollow\">password_verify<\/a>.<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435: <a href=\"https:\/\/github.com\/delphinpro\/php-auth-demo\" rel=\"noopener noreferrer nofollow\"><u>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 Github<\/u><\/a>.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/665602\/\"> https:\/\/habr.com\/ru\/post\/665602\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041c\u043d\u043e\u0433\u0438\u0435 \u043d\u043e\u0432\u0438\u0447\u043a\u0438 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 \u0442\u0443\u043f\u0438\u043a \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 PHP. \u041d\u0430 \u0422\u043e\u0441\u0442\u0435\u0440\u0435 \u0441 \u0437\u0430\u0432\u0438\u0434\u043d\u043e\u0439 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u043f\u0430\u0440\u043e\u043b\u044c \u0441 \u043f\u0430\u0440\u043e\u043b\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0438\u0437 \u0444\u043e\u0440\u043c\u044b \u043b\u043e\u0433\u0438\u043d\u0430. \u0417\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u043a\u0440\u0430\u0442\u043a\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f-\u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443.<\/p>\n<p><strong>Disclaimer:<\/strong> \u0441\u0442\u0430\u0442\u044c\u044f \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u0430 \u043d\u0430 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u044b\u0445 \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432. \u0423\u043c\u0443\u0434\u0440\u0451\u043d\u043d\u044b\u0435 \u043e\u043f\u044b\u0442\u043e\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0437\u0434\u0435\u0441\u044c \u043d\u0435 \u043d\u0430\u0439\u0434\u0443\u0442, \u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043d\u0435\u0434\u043e\u0447\u0451\u0442\u044b =).<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 MySQL\/MariaDB, PHP, <a href=\"https:\/\/www.php.net\/manual\/ru\/book.pdo.php\" rel=\"noopener noreferrer nofollow\">PDO<\/a>, <a href=\"https:\/\/www.php.net\/manual\/ru\/ref.password.php\" rel=\"noopener noreferrer nofollow\">\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0430\u0440\u043e\u043b\u044f\u043c\u0438<\/a>, \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0432\u043e\u0437\u044c\u043c\u0451\u043c <a href=\"https:\/\/getbootstrap.com\/\" rel=\"noopener noreferrer nofollow\">bootstrap<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u0430\u0437\u0443. \u041f\u0443\u0441\u0442\u044c \u043e\u043d\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f php-auth-demo. \u0412 \u043d\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 <code>users<\/code>:<\/p>\n<pre><code class=\"sql\">CREATE TABLE `users` (     `id` int unsigned NOT NULL AUTO_INCREMENT,     `username` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,     `password` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,     PRIMARY KEY (`id`),     UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043d\u0444\u0438\u0433 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0435.<\/p>\n<p><em>\u0418\u043c\u0435\u0439\u0442\u0435 \u0432\u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043a \u043a\u043e\u043d\u0444\u0438\u0433\u0430\u043c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438\u0437 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430, \u0438 \u043e\u043d\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0432\u0435\u0440\u0441\u0438\u0439, \u0432\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u0440\u043e\u043c\u0435\u0442\u0430\u0446\u0438\u0438 \u0443\u0447\u0435\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/em><\/p>\n<p><code>config.php<\/code><\/p>\n<pre><code class=\"php\">&lt;?php  return [     'db_name' => 'php-auth-demo',     'db_host' => '127.0.0.1',     'db_user' => 'mysql',     'db_pass' => 'mysql', ];<\/code><\/pre>\n<p>\u0418 \u0441\u0434\u0435\u043b\u0430\u0435\u043c &#171;\u0437\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u044b\u0439&#187; \u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<p><em>\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. \u041d\u043e \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u0441\u0442\u0430\u0442\u044c\u0438, \u0438 \u0432 \u0434\u0435\u043c\u043e-\u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u043e\u0431\u043e\u0439\u0434\u0451\u043c\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c.<\/em><\/p>\n<p>\u0412 &#171;\u0437\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u043c&#187; \u0444\u0430\u0439\u043b\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u044e \u0438 \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0438. <\/p>\n<p><code>boot.php<\/code><\/p>\n<pre><code class=\"php\">&lt;?php  \/\/ \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u0435\u0441\u0441\u0438\u044e session_start();  \/\/ \u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432 \u0411\u0414 function pdo(): PDO {     static $pdo;      if (!$pdo) {         $config = include __DIR__.'\/config.php';         \/\/ \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0411\u0414         $dsn = 'mysql:dbname='.$config['db_name'].';host='.$config['db_host'];         $pdo = new PDO($dsn, $config['db_user'], $config['db_pass']);         $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);     }      return $pdo; }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>pdo()<\/code> \u0434\u0430\u0441\u0442 \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443 PDO \u0432 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0444\u043e\u0440\u043c\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438. \u0420\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u0435\u0451 \u043f\u0440\u044f\u043c\u043e \u0432 \u0444\u0430\u0439\u043b\u0435 <code>index.php<\/code>.<\/p>\n<pre><code class=\"xml\">&lt;form method=\"post\" action=\"do_register.php\">   &lt;div class=\"mb-3\">     &lt;label for=\"username\" class=\"form-label\">Username&lt;\/label>     &lt;input type=\"text\" class=\"form-control\" id=\"username\" name=\"username\" required>   &lt;\/div>   &lt;div class=\"mb-3\">     &lt;label for=\"password\" class=\"form-label\">Password&lt;\/label>     &lt;input type=\"password\" class=\"form-control\" id=\"password\" name=\"password\" required>   &lt;\/div>   &lt;button type=\"submit\" class=\"btn btn-primary\">Register&lt;\/button> &lt;\/form><\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e: \u0434\u0432\u0430 \u043f\u043e\u043b\u044f, \u043a\u043d\u043e\u043f\u043a\u0430 \u0438 \u0444\u043e\u0440\u043c\u0430, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0444\u0430\u0439\u043b <code>do_register.php<\/code> \u043c\u0435\u0442\u043e\u0434\u043e\u043c POST. \u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u043f\u0438\u0448\u0435\u043c \u0432 \u0444\u0430\u0439\u043b\u0435 <code>do_register.php<\/code>.<\/p>\n<pre><code class=\"php\">&lt;?php  require_once __DIR__.'\/boot.php';  \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u043d\u0435 \u0437\u0430\u043d\u044f\u0442\u043e \u043b\u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f $stmt = pdo()->prepare(\"SELECT * FROM `users` WHERE `username` = :username\"); $stmt->execute(['username' => $_POST['username']]); if ($stmt->rowCount() > 0) {     flash('\u042d\u0442\u043e \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0443\u0436\u0435 \u0437\u0430\u043d\u044f\u0442\u043e.');     header('Location: \/'); \/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0442 \u043d\u0430 \u0444\u043e\u0440\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438     die; \/\/ \u041e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u0430 }  \/\/ \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0431\u0430\u0437\u0443 $stmt = pdo()->prepare(\"INSERT INTO `users` (`username`, `password`) VALUES (:username, :password)\"); $stmt->execute([     'username' => $_POST['username'],     'password' => password_hash($_POST['password'], PASSWORD_DEFAULT), ]);  header('Location: login.php');<\/code><\/pre>\n<p>\u0412 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u043d\u0430\u0448 &#171;\u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a&#187;.<\/p>\n<p>\u041f\u043e\u0442\u043e\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u043d\u0435 \u0437\u0430\u043d\u044f\u0442\u043e \u043b\u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0443\u043a\u0430\u0437\u0430\u0432 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0438\u0437 \u0444\u043e\u0440\u043c\u044b \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0437\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/www.php.net\/manual\/ru\/pdo.prepared-statements.php\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/a>, \u0447\u0442\u043e \u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u0438\u0442 \u043d\u0430\u0441 \u043e\u0442 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%92%D0%BD%D0%B5%D0%B4%D1%80%D0%B5%D0%BD%D0%B8%D0%B5_SQL-%D0%BA%D0%BE%D0%B4%D0%B0\" rel=\"noopener noreferrer nofollow\">SQL-\u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0439<\/a>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u044b, \u0430 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u0443\u0435\u043c \u0441 \u043d\u0438\u043c\u0438 \u043d\u0435\u043d\u0430\u0434\u0451\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u043d\u0435\u043d\u0430\u0434\u0451\u0436\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 \u0432\u043d\u0435 \u2013 $_GET, $_POST, $_REQUEST, $_COOCKIE). \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0451\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a. \u0415\u0441\u043b\u0438 \u0438\u0445 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f, \u0442\u043e \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0443\u0436\u0435 \u0437\u0430\u043d\u044f\u0442\u043e. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438 \u0432\u0435\u0440\u043d\u0451\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0444\u043e\u0440\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p><em>\u042f \u043d\u0430\u043f\u0438\u0441\u0430\u043b &#171;\u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f&#187;, \u043d\u043e \u043f\u043e \u0444\u0430\u043a\u0442\u0443, \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u043e\u043b\u0435 <\/em><code>username<\/code><em> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435, <\/em><code>rowCount()<\/code><em> \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043b\u0438\u0448\u044c \u0434\u0432\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f: <\/em><code>0<\/code><em> \u0438 <\/em><code>1<\/code><em>.<\/em><\/p>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043a\u043e\u0434\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>flash()<\/code>. \u0414\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f &#171;\u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u044b\u0445&#187; \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0415\u0441\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0435\u0451 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c, \u0442\u043e \u043e\u043d\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442 \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u0441\u0435\u0441\u0441\u0438\u0438, \u0430 \u0435\u0441\u043b\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0442\u043e \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u0438\u0437 \u0441\u0435\u0441\u0441\u0438\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u0442\u0435\u043c \u0443\u0434\u0430\u043b\u0438\u0442 \u0435\u0433\u043e \u0432 \u0441\u0435\u0441\u0441\u0438\u0438. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u0444\u0430\u0439\u043b <code>boot.php<\/code>.<\/p>\n<pre><code class=\"php\">function flash(?string $message = null) {     if ($message) {         $_SESSION['flash'] = $message;     } else {         if ($_SESSION['flash']) { ?>           &lt;div class=\"alert alert-danger mb-3\">               &lt;?=$_SESSION['flash']?>           &lt;\/div>         &lt;?php }         unset($_SESSION['flash']);     } }<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u0435\u0451 \u043da \u0444\u043e\u0440\u043c\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"xml\">&lt;h1 class=\"mb-5\">Registration&lt;\/h1>  &lt;?php flash(); ?>  &lt;form method=\"post\" action=\"do_register.php\">     &lt;!-- ... --> &lt;\/form><\/code><\/pre>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0433\u043e\u0442\u043e\u0432.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043e\u0434 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u0448\u0435, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u043c\u044b \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043b\u043e\u0433\u0438\u043d\u0430. \u0421\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0435\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c.<\/p>\n<p><code>login.php<\/code><\/p>\n<pre><code class=\"xml\">&lt;h1 class=\"mb-5\">Login&lt;\/h1>  &lt;?php flash() ?>  &lt;form method=\"post\" action=\"do_login.php\">     &lt;div class=\"mb-3\">         &lt;label for=\"username\" class=\"form-label\">Username&lt;\/label>         &lt;input type=\"text\" class=\"form-control\" id=\"username\" name=\"username\" required>     &lt;\/div>     &lt;div class=\"mb-3\">         &lt;label for=\"password\" class=\"form-label\">Password&lt;\/label>         &lt;input type=\"password\" class=\"form-control\" id=\"password\" name=\"password\" required>     &lt;\/div>     &lt;div class=\"d-flex justify-content-between\">         &lt;button type=\"submit\" class=\"btn btn-primary\">Login&lt;\/button>         &lt;a class=\"btn btn-outline-primary\" href=\"index.php\">Register&lt;\/a>     &lt;\/div> &lt;\/form><\/code><\/pre>\n<p>\u0412 \u0432\u0438\u0434\u0443 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043e\u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442 \u0444\u043e\u0440\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043b\u043e\u0433\u0438\u043d\u0430 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>do_login.php<\/code>.<\/p>\n<p><code>do_login.php<\/code><\/p>\n<pre><code>&lt;?php  require_once __DIR__.'\/boot.php';  \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u044e\u0437\u0435\u0440\u043d\u0435\u0439\u043c\u043e\u043c $stmt = pdo()->prepare(\"SELECT * FROM `users` WHERE `username` = :username\"); $stmt->execute(['username' => $_POST['username']]); if (!$stmt->rowCount()) {     flash('\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d');     header('Location: login.php');     die; } $user = $stmt->fetch(PDO::FETCH_ASSOC);  \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043f\u0430\u0440\u043e\u043b\u044c if (password_verify($_POST['password'], $user['password'])) {     \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043d\u043e\u0432\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c     \/\/ \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c     \/\/ \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442\u0435 \u043e\u043f\u0446\u0438\u0438 \u0445\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f     if (password_needs_rehash($user['password'], PASSWORD_DEFAULT)) {         $newHash = password_hash($_POST['password'], PASSWORD_DEFAULT);         $stmt = pdo()->prepare('UPDATE `users` SET `password` = :password WHERE `username` = :username');         $stmt->execute([             'username' => $_POST['username'],             'password' => $newHash,         ]);     }     $_SESSION['user_id'] = $user['id'];     header('Location: \/');     die; }  flash('\u041f\u0430\u0440\u043e\u043b\u044c \u043d\u0435\u0432\u0435\u0440\u0435\u043d'); header('Location: login.php');<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0432\u0430\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u041c\u044b \u043d\u0435 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u043e \u043f\u0430\u0440\u0435 <em>username\/password<\/em>, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e <em>username<\/em>. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0445\u0435\u0448\u0438\u0440\u0443\u0435\u0442\u0435 \u043f\u0440\u0438\u0448\u0435\u0434\u0448\u0438\u0439 \u0438\u0437 \u0444\u043e\u0440\u043c\u044b \u043b\u043e\u0433\u0438\u043d\u0430 \u043f\u0430\u0440\u043e\u043b\u044c \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u0442\u0435 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0445\u0435\u0448 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u043c \u0432 \u0431\u0430\u0437\u0435, \u0432\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435. <code>Password_hash()<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u0443\u044e \u0441\u043e\u043b\u044c \u0434\u043b\u044f \u043f\u0430\u0440\u043e\u043b\u0435\u0439 \u0438 \u0445\u0435\u0448\u0438 \u0431\u0443\u0434\u0443\u0442 <em>\u0432\u0441\u0435\u0433\u0434\u0430<\/em> \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u0437\u043d\u044b\u0435. \u0412\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>password_hash<\/code>, \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u043e\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437  \u0434\u043b\u044f \u043f\u0430\u0440\u043e\u043b\u044f &#171;123&#187;:<\/p>\n<pre><code>$2y$10$loqucup11.3DL1fgDWanoettFpFJuFFd0fY6BZyiP698ZqvA4tmuy $2y$10$.LF3OzmQRtJvuZZWeWF.2u80x3ls6OEAU5J9gLHDtcYrFzJkRRPvq $2y$10$iGj\/nOCavShd2vbMZTC4GOMYCqDj2YSc8qWoeqjVbD1xaKU2CgAfi<\/code><\/pre>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>password_verify<\/code> \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0430\u0440\u043e\u043b\u044f. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0434\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0434\u043b\u044f <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%90%D1%82%D0%B0%D0%BA%D0%B0_%D0%BF%D0%BE_%D0%B2%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%B8\" rel=\"noopener noreferrer nofollow\">\u0430\u0442\u0430\u043a \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/a>.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043f\u0430\u0440\u043e\u043b\u044c \u043d\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0445\u0435\u0448\u0430, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0432\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0445\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u0435\u0433\u043e \u043e\u043f\u0446\u0438\u0438.<\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u043b\u043e\u0433\u0438\u043d\u0430 \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0441\u0435\u0441\u0441\u0438\u0438, \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u043e\u0433\u043e \u0444\u0430\u043a\u0442\u0430, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0435\u043d, \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0432 \u0441\u0435\u0441\u0441\u0438\u0438. \u041c\u044b \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u0438 \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u0435\u0435 \u0432 \u0442\u043e\u043c \u0436\u0435 \u0444\u0430\u0439\u043b\u0435 <code>boot.php<\/code>.<\/p>\n<pre><code class=\"php\">function check_auth(): bool {     return !!($_SESSION['user_id'] ?? false); }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d.<\/p>\n<pre><code class=\"xml\">&lt;?php require_once __DIR__.'\/boot.php';  $user = null;  if (check_auth()) {     \/\/ \u041f\u043e\u043b\u0443\u0447\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u043c\u0443 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443     $stmt = pdo()->prepare(\"SELECT * FROM `users` WHERE `id` = :id\");     $stmt->execute(['id' => $_SESSION['user_id']]);     $user = $stmt->fetch(PDO::FETCH_ASSOC); } ?> &lt;?php if ($user) { ?>      &lt;h1>Welcome back, &lt;?=$user['username']?>!&lt;\/h1>      &lt;form class=\"mt-5\" method=\"post\" action=\"do_logout.php\">         &lt;button type=\"submit\" class=\"btn btn-primary\">Logout&lt;\/button>     &lt;\/form>  &lt;?php } else { ?>      &lt;h1 class=\"mb-5\">Registration&lt;\/h1>      &lt;?php flash(); ?>      &lt;form method=\"post\" action=\"do_register.php\">         &lt;!-- ... -->     &lt;\/form>  &lt;?php } ?><\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0444\u043e\u0440\u043c\u0435 \u043b\u043e\u0433\u0438\u043d\u0430, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u0436\u0435 \u0432\u043e\u0448\u0451\u043b:<\/p>\n<p><code>login.php<\/code><\/p>\n<pre><code class=\"php\">&lt;?php  require_once<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-333083","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/333083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=333083"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/333083\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=333083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=333083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=333083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}