Secure User Authentication System Using PHP & MySQL
In this project, I built a simple authentication system inspired by Facebook. PHP MySQL HTML / CSS XAMPP Features User registration with validation This project was developed as a team of five members. We collaborated to design, build, and improve different parts of the application. The system uses a users table to store user information. Passwords are hashed using password_hash() for security. sql users( idint(11) NOT NULL AUTO_INCREMENT, nomvarchar(100) NOT NULL, prenomvarchar(100) NOT NULL, contactvarchar(100) NOT NULL, passwordvarchar(255) NOT NULL, jourint(2) NOT NULL, moisint(2) NOT NULL, anneeint(4) NOT NULL, genretinyint(1) NOT NULL, created_attimestamp NOT NULL DEFAULT current_timestamp(), id) Database Connection (PDO) `fetch(PDO::FETCH_ASSOC); if($user && password_verify($password, $user['password'])){ $_SESSION['user'] = $user; header("Location: accueil.php"); exit(); } else { $message = "Mot de passe ou contact incorrect !"; } } } ?>` This is a protected page. It starts by checking if $_SESSION['user'] exists; if not, it redirects to login.php. It displays the logged-in user's name and a list of other users as "friend suggestions". I used CSS Flexbox and Media Queries to make the layout responsive on mobile. The "Add Friend" button uses JavaScript fetch to call add_friend.php without reloading the page. if (!isset($_SESSION['user'])) { $user = $_SESSION['user']; $stmt = $pdo->prepare("SELECT * FROM users WHERE id != ?"); This file performs the final verification. It uses password_verify() to compare the password entered in confirm.php with the hashed password stored in the session. If they match, it inserts the new user into the users table using a prepared statement for security. Finally, it clears the temporary session and redirects to the success page. if(!isset($_SESSION['temp_user'])){ if($_SERVER["REQUEST_METHOD"] == "POST") { $input_password = $_POST['password']; $user = $_SESSION['temp_user']; if(password_verify($input_password, $user['password'])) { $sql = "INSERT INTO users (nom, prenom, contact, password, jour, mois, annee, genre) VALUES (:nom, :prenom, :contact, :password, :jour, :mois, :annee, :genre)"; $stmt = $pdo->prepare($sql); $stmt->execute([ ':nom' => $user['nom'], ':prenom' => $user['prenom'], ':contact' => $user['contact'], ':password' => $user['password'], ':jour' => $user['jour'], ':mois' => $user['mois'], ':annee' => $user['annee'], ':genre' => $user['genre'] ]); unset($_SESSION['temp_user']); header("Location: succes.php"); exit(); } else { header("Location: confirm.php"); exit(); } } ?>` I learned how to create a registration and login system similar to real applications. You can find the full project on GitHub here: https://github.com/Nouhailasemoud/login-system-php
