From 7ed294e4e5cd952fdc267f82c3c771dfa15a5cbb Mon Sep 17 00:00:00 2001 From: "Igor Barkov (iwork)" Date: Thu, 27 Aug 2020 16:50:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B5=D0=B7=D0=B4=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BD=D0=BE=D0=B2=D1=83=D1=8E=20=D0=B1=D0=B0?= =?UTF-8?q?=D0=B7=D1=83,=20=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20=D1=82=D0=BE?= =?UTF-8?q?=D1=87=D0=BD=D0=BE=D0=B5=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=D0=BA,=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81=20=D0=BE?= =?UTF-8?q?=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20=D0=B2=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BD=D1=82=D1=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rememberpassword.php | 61 +++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/rememberpassword.php b/rememberpassword.php index 7b18c50..6869e63 100644 --- a/rememberpassword.php +++ b/rememberpassword.php @@ -1,6 +1,12 @@ query('SELECT `email` FROM `users` WHERE `login` = "?s"', $login)->fetch_assoc(); - $hash = bin2hex(random_bytes(8)); - $lasttime = date('Y-m-d', strtotime('+1days')); - $ip = $_SERVER['REMOTE_ADDR']; - - if (db::c()->query('INSERT INTO `confirmpasswd` (`login`, hash, `date`, `ip`) VALUES ("?s", "?s", "?s", "?s")', $login, $hash, $lasttime, $ip)) { - $message = "Здравствуйте!

+ $recovery = db::c()->query('SELECT 1 FROM users_recovery WHERE login = "?s"', $login); + if ($recovery->getNumRows()) { + $sql = db::c()->query('SELECT email FROM users WHERE login = "?s"', $login)->fetch_assoc(); + if ($sql) { + $hash = bin2hex(random_bytes(8)); + $lasttime = date('Y-m-d', strtotime('+1days')); + $ip = $_SERVER['REMOTE_ADDR']; + db::c()->query('INSERT INTO users_recovery (login, hash, ip, date) VALUES ("?s", "?s", "?s", "?s")', $login, $hash, $lasttime, $ip); + $message = "Здравствуйте!

Кто-то запросил восстановление пароля к вашему персонажу " . $login . ".

Для смены пароля пройдите по данной ссылке.

Ссылка будет действовать до " . date('d-M-Y', $lasttime) . ". "; - if (mail_send($sql['email'], "Noreply", "noreply@" . GAMEDOMAIN, "Восстановление забытого пароля", $message)) { - $statusMessage = 'Письмо отправлено.'; - } else $statusMessage = 'Ошибка: письмо не отправлено!'; - } else $statusMessage = 'Ошибка: имя пользователя не существует!'; + if (mail_send($sql['email'], "Noreply", "noreply@" . GAMEDOMAIN, "Восстановление забытого пароля", $message)) { + $statusMessage = OK_MAIL_SENT; + } else { + $statusMessage = ERROR_MAIL_NOT_SENT; + } + } else { + $statusMessage = ERROR_NO_SUCH_USER; + } + } else { + $statusMessage = ERROR_TOO_MANY_TRIES; + } } $allowChange = false; $changePassword = filter_input(INPUT_GET, 'change'); if ($changePassword) { - if (db::c()->query('SELECT 1 FROM `confirmpasswd` WHERE `hash` = "?s" AND `date` < "?s"', $changePassword, date('Y-m-d'))->getNumRows()) + if (db::c()->query('SELECT 1 FROM users_recovery WHERE `hash` = "?s" AND `date` < "?s"', $changePassword, date('Y-m-d'))->getNumRows()) { $allowChange = true; - else $statusMessage = 'Ошибка: ссылка устарела!'; + } + else { + $statusMessage = ERROR_OLD_HASH; + } } -if (!empty($_POST['newpasswd']) AND !empty($_POST['hashcheck'])) { - $query = db::c()->query('SELECT `login` FROM `confirmpasswd` WHERE hash = "?s"', $_POST['hashcheck']); +if (!empty($_POST['newpasswd']) && !empty($_POST['hashcheck'])) { + $query = db::c()->query('SELECT login FROM users_recovery WHERE hash = "?s"', $_POST['hashcheck']); if ($query->getNumRows()) { $query->fetch_assoc(); $passwordHashed = password_hash($_POST['newpasswd'], PASSWORD_DEFAULT); - db::c()->query('UPDATE `users` SET `pass` = "?s" WHERE `login` = "?s"', $passwordHashed, $query['login']); - db::c()->query('DELETE FROM `confirmpasswd` WHERE `hash` = "?s"', $_POST['hashcheck']); - $statusMessage = 'Пароль изменен!'; - } else $statusMessage = 'Ошибка: неверная ссылка!'; - + db::c()->query('UPDATE users SET pass = "?s" WHERE login = "?s"', $passwordHashed, $query['login']); + db::c()->query('DELETE FROM confirmpasswd WHERE hash = "?s"', $_POST['hashcheck']); + $statusMessage = OK_PASSWORD_CHANGED; + } else { + $statusMessage = ERROR_WRONG_HASH; + } } ?>