<pre><?php include "dbconn.php"; if (isset($_POST['submit'])) { try { $cuid = $_POST['username']; $cpass = $_POST['password']; // Check if username exists in Clients table $stmt = $pdo->prepare("SELECT * FROM clients WHERE cuid = :cuid"); $stmt->execute(array(':cuid' => $cuid)); $result = $stmt->fetch(); if ($result) { if (password_verify($cpass, $result['cpass'])) { header("Location: dashboard.html"); exit; } else { echo "Invalid password"; } } else { // Check if username exists in SubUser table $stmt = $pdo->prepare("SELECT * FROM SubUser WHERE SubUsrID = :cuid"); $stmt->execute(array(':cuid' => $cuid)); $result = $stmt->fetch(); if ($result) { if (password_verify($cpass, $result['SubUsrPass1'])) { header("Location: dashboard-Sub.html"); exit; } else { echo "Invalid password"; } } else { // Check if username exists in BervEmp table $stmt = $pdo->prepare("SELECT * FROM BervEmp WHERE BerEmpID = :cuid"); $stmt->execute(array(':cuid' => $cuid)); $result = $stmt->fetch(); if ($result) { if (password_verify($cpass, $result['pass'])) { header("Location: empdashboard.html"); exit; } else { echo "Invalid password"; } } else { echo "Invalid username"; } } } } catch (PDOException $e) { echo "Error: " . $e->getMessage(); } } ?>
<pre><?php class Db { private $dsn; private $user; private $password; private $pdo; public function __construct($dsn, $user, $password) { $this->dsn = $dsn; $this->user = $user; $this->password = $password; } private function connect() { try { $this->pdo = new PDO($this->dsn, $this->user, $this->password); } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage(); } } public function getPdo() { if (!$this->pdo) { $this->connect(); } return $this->pdo; } } $dsn = "pgsql:host=localhost;dbname=Beravaa"; $user = "postgres"; $password = "222222"; $db = new Db($dsn, $user, $password); $pdo = $db->getPdo(); if ($pdo) { echo "Connected to the database successfully"; } else { echo "Failed to connect to the database"; } ?>
echo "Invalid password in my Login";
echo "Invalid password as the User Exist in SubUser Table";
echo "Invalid password as the User Exist in BervEmp Table";
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)