35580-vm/login.php
Flatlogic Bot 79236554fd UB
2025-11-09 01:47:20 +00:00

84 lines
3.3 KiB
PHP

<?php
session_start();
ini_set('display_errors', 0);
// If user is already logged in, redirect to dashboard
if (isset($_SESSION['user_id'])) {
header("Location: dashboard.php");
exit();
}
require_once 'db/config.php';
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$mobile_number = trim($_POST['mobile_number'] ?? '');
$password = $_POST['password'] ?? '';
if (empty($mobile_number) || empty($password)) {
$error_message = 'Please enter both mobile number and password.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT id, password_hash FROM users WHERE mobile_number = :mobile_number");
$stmt->execute(['mobile_number' => $mobile_number]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password_hash'])) {
// Password is correct, start session
$_SESSION['user_id'] = $user['id'];
header("Location: dashboard.php");
exit();
} else {
$error_message = 'Invalid mobile number or password.';
}
} catch (PDOException $e) {
$error_message = 'An internal error occurred. Please try again later.';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login - UBPay</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-md-6 col-lg-4">
<div class="card mt-5">
<div class="card-body">
<h3 class="card-title text-center mb-4">Login to UBPay</h3>
<?php if (!empty($error_message)): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
<?php endif; ?>
<form action="login.php" method="post">
<div class="mb-3">
<label for="mobile_number" class="form-label">Mobile Number</label>
<input type="text" class="form-control" id="mobile_number" name="mobile_number" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Login</button>
</div>
<p class="text-center mt-3">
Don't have an account? <a href="index.php">Register</a>
</p>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>