*Poze / Video (obligatoriu):
![[C++/Py] [WEB] Sentry System FULL (e-mail code for login) - Mesaj 1 - Imagine 1 [C++/Py] [WEB] Sentry System FULL (e-mail code for login) - Mesaj 1 - Imagine 1](https://i.imgur.com/YVcIiGw.png)
*Link download:
![[C++/Py] [WEB] Sentry System FULL (e-mail code for login) - Mesaj 1 - Imagine 1 [C++/Py] [WEB] Sentry System FULL (e-mail code for login) - Mesaj 1 - Imagine 1](https://i.imgur.com/YVcIiGw.png)
Zeci de resurse Metin2 Premium - exclusive și 100% funcționale începând cu 15.99€!.
Vezi resursele Cumpără premium
<?php
// === CONFIGURATION ===
define('DB_HOST', 'Server IP');
define('DB_USER', 'root');
define('DB_PASS', 'Password');
define('DB_NAME', 'account');
define('SMTP_HOST', 'smtp.gmail.com');
define('SMTP_PORT', 465);
define('SMTP_USER', '[email protected]');
define('SMTP_PASS', '123');
define('MAIL_FROM', SMTP_USER);
define('MAIL_NAME', 'Server Name');
define('MAIL_SUBJECT', 'Suspicious Login Notification');
error_reporting(0);
// === DATABASE UTILITIES ===
function connectToDatabase(): PDO
{
try {
$pdo = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8", DB_USER, DB_PASS);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo;
} catch (PDOException $e) {
exit("web_sql_error");
}
}
function logError(string $source, string $message): void
{
$log = sprintf("Error caught from: %s\nError: %s\n", $source, $message);
file_put_contents("errors.txt", $log, FILE_APPEND);
}
// === AUTHENTICATION ===
function getUserData(PDO $conn, string $login, string $password): array
{
$stmt = $conn->prepare("
SELECT * FROM `account`
WHERE `login` = :login
AND `password` = PASSWORD(:password)
");
$stmt->execute(['login' => $login, 'password' => $password]);
if ($stmt->rowCount() !== 1) {
exit("web_unknown_error");
}
return $stmt->fetch(PDO::FETCH_ASSOC);
}
function verifyGuard(array $user, string $userCode, string $currentIp): void
{
// If IP matches or guard is disabled, allow access
if ($user['guard_ip'] === $currentIp || (int)$user['guard_status'] === 0) {
exit("guard_is_ok");
}
$guardActive = (int)$user['guard_status'] === 2;
$recentCode = (time() - (int)$user['guard_date']) < 18000; // 5 hours
// If a guard code was recently sent, validate it
if ($guardActive || $recentCode) {
if ($userCode == 0) {
exit("code_already_sended");
}
if ($userCode === $user['guard_code']) {
exit("code_is_valid");
} else {
exit("code_is_invalid");
}
}
}
// === EMAIL SENDING ===
function sendGuardCode(string $toEmail, string $name, string $login, string $date): string
{
include_once('PHPMailer/class.phpmailer.php');
$code = (string)rand(100000, 999999);
$mail = new PHPMailer();
$mail->SetFrom(MAIL_FROM, MAIL_NAME);
$mail->AddAddress($toEmail);
$mail->Subject = MAIL_SUBJECT;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = SMTP_HOST;
$mail->Port = SMTP_PORT;
$mail->Username = SMTP_USER;
$mail->Password = SMTP_PASS;
$mail->MsgHTML("
Hello $name,<br/><br/>
A login attempt was made to your account on <strong>$date</strong>.<br/>
If this was not you, please change your password immediately.<br/><br/>
<strong>Your activation code:</strong><br/><br/>
<h2>$code</h2><br/><br/>
---<br/>
<em>Do not reply to this email. It was generated automatically.</em><br/><br/>
MyServer Management<br/>
https://myserver.com
");
if (!$mail->Send()) {
logError('PHPMailer', $mail->ErrorInfo);
exit("mailer_error");
}
return $code;
}
// === MAIN EXECUTION ===
$login = trim($_GET['login'] ?? '');
$password = trim($_GET['password'] ?? '');
$guardCodeInput = $_GET['guard_code'] ?? '0';
$clientIp = $_SERVER['REMOTE_ADDR'];
$currentDate = date("Y-m-d H:i:s");
// Exit early if required fields are missing
if ($login === '' || $password === '') {
exit;
}
// Process user login and guard system
$pdo = connectToDatabase();
$user = getUserData($pdo, $login, $password);
verifyGuard($user, $guardCodeInput, $clientIp);
// Send new guard code via email
$code = sendGuardCode(
$user['email'],
$user['real_name'],
$login,
$currentDate
);
// Save code and update guard status in database
$update = $pdo->prepare("
UPDATE account
SET guard_status = 2, guard_code = :code, guard_date = UNIX_TIMESTAMP()
WHERE login = :login
");
$update->execute([
'code' => $code,
'login' => $login
]);
echo "mail_is_sended";
?>
Te așteptăm și pe serverul de Discord - aici ne-am strâns toată comunitatea de Metin2 din România.
Alătură-te acum!
Trebuie să fii membru pentru a răspunde
Membrii pot crea subiecte noi și pot descărca resurse Metin2 Gratuit!
Te poți înregistra sau conecta rapid utilizând contul tău de Discord, Github sau Google.
Utilizatori ce navighează pe acest forum: mcncc și 24 vizitatori