unsure. Here is my entire login page. I use recaptcha and IP checks, but you can ignore that and see if you can mix and match some code to fit your needs. My HTML is different, so just look at the code and see if anything is useful for you. I dont knwo why you would see a blank page. I tested it and that isnt what I saw, but I am using custom code, so things may not match up always. This also has my terrible attempt at password visibility toggle. I like yours better. I will play with that more when I have more time.
<?php
//crap mainly. filter username and pass. Prepare, bind and other assorted stupid shit
require_once("backend/functions.php");
dbconn();
session_start();
$site_config["LEFTNAV"] = $site_config["MIDDLENAV"] = $site_config["RIGHTNAV"] = false;
if (isset($_POST["username"]) && isset($_POST["password"])) {
if (!empty($_POST["username"]) && !empty($_POST["password"])) {
$username = filter_var($_POST["username"], FILTER_SANITIZE_STRING);
$password = filter_var($_POST["password"], FILTER_SANITIZE_STRING);
$password_hash = passhash($password);
$stmt = $GLOBALS["DBconnector"]->prepare("SELECT id, password, secret, status, enabled FROM users WHERE username = ? LIMIT 1");
$stmt->bind_param("s", $username);
$stmt->execute();
if ($stmt->error) {
die("Query failed: " . $stmt->error);
}
$res = $stmt->get_result();
$row = $res->fetch_assoc();
if ($row) {
if ($row["password"] !== $password_hash) {
$message = T_("LOGIN_INCORRECT");
} elseif ($row["status"] === "pending") {
$message = T_("ACCOUNT_PENDING");
} elseif ($row["enabled"] === "no") {
$message = T_("ACCOUNT_DISABLED");
} else {
// CAPTCHA validation
if (isset($_POST['g-recaptcha-response'])) {
$captcha = $_POST['g-recaptcha-response'];
if (!$captcha) {
echo "<script>alert('Please Check the Captcha box');</script>";
} else {
$secretKey = $site_config['SECRET'];
$ip = $_SERVER['REMOTE_ADDR'];
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$captcha&remoteip=$ip");
$response = json_decode($response);
if ($response->success === true) {
// Login successful
logincookie($row["id"], $row["password"], $row["secret"]);
// IP history edits
$now = get_date_time();
$stmt = $GLOBALS["DBconnector"]->prepare("INSERT INTO iplog (ip, userid, added, lastused) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE timesused=timesused+1, lastused=?");
$stmt->bind_param("sissi", getip(), $row["id"], $now, $now, $now);
$stmt->execute();
if (!empty($_POST["returnto"])) {
header("Location: " . $_POST["returnto"]);
} else {
header("Location: index.php");
}
die();
} else {
echo "<script>alert('CAPTCHA_INVALID');</script>";
}
}
} else {
echo "<script>alert('CAPTCHA_MISSING');</script>";
}
}
} else {
$message = T_("LOGIN_INCORRECT");
}
} else {
$message = T_("NO_EMPTY_FIELDS");
}
if ($message) {
show_error_msg(T_("ACCESS_DENIED"), $message, 1);
}
}
logoutcookie();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $site_config['SITENAME']; ?></title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/fontawesome-all.min.css">
<link rel="stylesheet" type="text/css" href="css/iofrm-style.css">
<link rel="stylesheet" type="text/css" href="css/iofrm-theme14.css">
<style>
body {
min-height: 100vh;
}
</style>
</head>
<body>
<div class="form-body" class="container-fluid">
<div class="row">
<div class="form-holder">
<div class="form-content">
<div class="form-items">
<div class="website-logo-inside">
<a href="index.html">
</a>
</div>
<h3>Please log in to your account.</h3>
<div class="page-links">
<a href="account-login.php" class="active">Login</a>
<a href="account-signup.php">Register</a>
<a href="account-recover.php">Recover Account</a>
<!-- <a href="contact.php">Contact us with problems</a> -->
</div>
<form method="post" action="account-login.php">
<input class="form-control" type="text" name="username" placeholder="Username" required>
<div class="password-container">
<input class="form-control" type="password" name="password" id="password" placeholder="Password" required>
<button type="button" id="togglePassword" class="password-toggle-btn" onclick="togglePasswordVisibility()">
Show
</button>
</div>
<center><div class="g-recaptcha" data-theme="light" data-sitekey="<?php echo $site_config['SITEKEY']; ?>"></div></center>
<?php
if (!empty($_REQUEST["returnto"])) {
print("<input type=\"hidden\" name=\"returnto\" value=\"" . cleanstr($_REQUEST["returnto"]) . "\" />\n");
}
?>
<div class="form-button">
<button id="submit" type="submit" class="ibtn">Login</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/popper.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function togglePasswordVisibility() {
var passwordInput = document.getElementById("password");
var toggleButton = document.getElementById("togglePassword");
if (passwordInput.type === "password") {
passwordInput.type = "text";
toggleButton.textContent = "Hide";
} else {
passwordInput.type = "password";
toggleButton.textContent = "Show";
}
}
</script>
</body>
</html>
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2023-07-01 15:42:45