<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: saoud aya</title>
    <description>The latest articles on DEV Community by saoud aya (@yasmin_aya_b981502107dd8e).</description>
    <link>https://dev.to/yasmin_aya_b981502107dd8e</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3890976%2Fd49cba7d-f1c0-4f60-87c3-78a6f60d5dbc.png</url>
      <title>DEV Community: saoud aya</title>
      <link>https://dev.to/yasmin_aya_b981502107dd8e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yasmin_aya_b981502107dd8e"/>
    <language>en</language>
    <item>
      <title>Secure User Authentication System Using PHP &amp; MySQL</title>
      <dc:creator>saoud aya</dc:creator>
      <pubDate>Tue, 21 Apr 2026 22:47:16 +0000</pubDate>
      <link>https://dev.to/yasmin_aya_b981502107dd8e/secure-user-authentication-system-using-php-mysql-1j2m</link>
      <guid>https://dev.to/yasmin_aya_b981502107dd8e/secure-user-authentication-system-using-php-mysql-1j2m</guid>
      <description>&lt;p&gt;In this project, I built a simple authentication system inspired by Facebook.&lt;br&gt;
The goal was to allow users to register, log in securely, and interact with a basic social interface.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tech Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;PHP&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MySQL&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;HTML / CSS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;XAMPP&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;p&gt;User registration with validation&lt;br&gt;
Secure login system&lt;br&gt;
Password hashing (password_hash)&lt;br&gt;
Session management&lt;br&gt;
Account confirmation step&lt;br&gt;
Friend suggestion system (basic)&lt;br&gt;
Responsive UI&lt;/p&gt;

&lt;h2&gt;
  
  
  Team Work
&lt;/h2&gt;

&lt;p&gt;This project was developed as a team of five members.&lt;br&gt;&lt;br&gt;
We collaborated to design, build, and improve different parts of the application.&lt;br&gt;
Working in a team helped me improve my communication, collaboration, and problem-solving skills.&lt;/p&gt;

&lt;h2&gt;
  
  
  Database Structure
&lt;/h2&gt;

&lt;p&gt;The system uses a &lt;code&gt;users&lt;/code&gt; table to store user information. Passwords are hashed using &lt;code&gt;password_hash()&lt;/code&gt; for security.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sql&lt;br&gt;
CREATE TABLE&lt;/code&gt;users&lt;code&gt;(&lt;br&gt;
&lt;/code&gt;id&lt;code&gt;int(11) NOT NULL AUTO_INCREMENT,&lt;br&gt;
&lt;/code&gt;nom&lt;code&gt;varchar(100) NOT NULL,&lt;br&gt;
&lt;/code&gt;prenom&lt;code&gt;varchar(100) NOT NULL,&lt;br&gt;
&lt;/code&gt;contact&lt;code&gt;varchar(100) NOT NULL,&lt;br&gt;
&lt;/code&gt;password&lt;code&gt;varchar(255) NOT NULL,&lt;br&gt;
&lt;/code&gt;jour&lt;code&gt;int(2) NOT NULL,&lt;br&gt;
&lt;/code&gt;mois&lt;code&gt;int(2) NOT NULL,&lt;br&gt;
&lt;/code&gt;annee&lt;code&gt;int(4) NOT NULL,&lt;br&gt;
&lt;/code&gt;genre&lt;code&gt;tinyint(1) NOT NULL,&lt;br&gt;
&lt;/code&gt;created_at&lt;code&gt;timestamp NOT NULL DEFAULT current_timestamp(),&lt;br&gt;
  PRIMARY KEY (&lt;/code&gt;id&lt;code&gt;)&lt;br&gt;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Database Connection (PDO)
&lt;/h2&gt;

&lt;p&gt;`&amp;lt;?php&lt;br&gt;
$host = "localhost";&lt;br&gt;
$dbname = "facebook";&lt;br&gt;
$user = "root";&lt;br&gt;
$pass = "";&lt;/p&gt;

&lt;p&gt;try {&lt;br&gt;
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $user, $pass);&lt;br&gt;
    $pdo-&amp;gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);&lt;br&gt;
} catch (PDOException $e) {&lt;br&gt;
    die("Erreur DB: " . $e-&amp;gt;getMessage());&lt;br&gt;
}&lt;br&gt;
?&amp;gt;`&lt;/p&gt;

&lt;h2&gt;
  
  
  Registration Page (Sign Up)
&lt;/h2&gt;

&lt;p&gt;This page allows users to create an account. I also created helper functions to dynamically generate the date of birth (day, month, year).&lt;br&gt;
`&amp;lt;?php&lt;/p&gt;

&lt;p&gt;function getYears($selectedYear = 1970) {&lt;br&gt;
    for ($year = 2026; $year &amp;gt;= 1905; $year--) {&lt;br&gt;
        $selected = ($year == $selectedYear) ? "selected" : "";&lt;br&gt;
        echo "$year";&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;function getMonths() {&lt;br&gt;
    $months = ["JANVIER", "FÉVRIER", "MARS", "AVRIL", "MAI", "JUIN", "JUILLET", "AOÛT", "SEPTEMBRE", "OCTOBRE", "NOVEMBRE", "DÉCEMBRE"];&lt;br&gt;
    foreach ($months as $index =&amp;gt; $m) {&lt;br&gt;
        $val = $index + 1;&lt;br&gt;
        echo "$m";&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;function getDays() {&lt;br&gt;
    for ($day = 1; $day &amp;lt;= 31; $day++) {&lt;br&gt;
        echo "$day";&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
?&amp;gt;&lt;br&gt;
`&lt;/p&gt;

&lt;h2&gt;
  
  
  authentication
&lt;/h2&gt;

&lt;p&gt;This is the login page. The PHP script checks if the contact and password fields are submitted. It queries the database for a user with the given contact, then uses password_verify() to check if the submitted password matches the stored hash. If successful, it stores the user data in $_SESSION['user'] and redirects to home.php.&lt;br&gt;
`&amp;lt;?php&lt;br&gt;
session_start();&lt;br&gt;
require_once 'database.php';&lt;br&gt;
$message = "";&lt;br&gt;
if(isset($_POST['connecter'])){&lt;br&gt;
    $contact = $_POST['contact'];&lt;br&gt;
    $password = $_POST['password'];&lt;br&gt;
    if(empty($contact) || empty($password)){&lt;br&gt;
        $message = "Tous les champs sont obligatoires";&lt;br&gt;
    } else {&lt;br&gt;
        $sql = "SELECT * FROM users WHERE contact = ?";&lt;br&gt;
        $stmt = $pdo-&amp;gt;prepare($sql);&lt;br&gt;
        $stmt-&amp;gt;execute([$contact]);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $user = $stmt-&amp;gt;fetch(PDO::FETCH_ASSOC);

    if($user &amp;amp;&amp;amp; password_verify($password, $user['password'])){

        $_SESSION['user'] = $user;

        header("Location: accueil.php");
       exit();
    } else {
        $message = "Mot de passe ou contact incorrect !";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
?&amp;gt;`&lt;/p&gt;

&lt;h2&gt;
  
  
  home
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
`&amp;lt;?php&lt;br&gt;
session_start();&lt;br&gt;
require_once "database.php";&lt;/p&gt;

&lt;p&gt;if (!isset($_SESSION['user'])) {&lt;br&gt;
    header("Location: login.php");&lt;br&gt;
    exit();&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;$user = $_SESSION['user'];&lt;/p&gt;

&lt;p&gt;$stmt = $pdo-&amp;gt;prepare("SELECT * FROM users WHERE id != ?");&lt;br&gt;
$stmt-&amp;gt;execute([$user['id']]);&lt;br&gt;
$friends = $stmt-&amp;gt;fetchAll(PDO::FETCH_ASSOC);&lt;br&gt;
?&amp;gt;`&lt;/p&gt;

&lt;h2&gt;
  
  
  verify
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
`&amp;lt;?php&lt;br&gt;
session_start();&lt;br&gt;
require_once 'database.php';&lt;/p&gt;

&lt;p&gt;if(!isset($_SESSION['temp_user'])){&lt;br&gt;
    die("Session expirée");&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;if($_SERVER["REQUEST_METHOD"] == "POST") {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$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-&amp;gt;prepare($sql);

    $stmt-&amp;gt;execute([
        ':nom' =&amp;gt; $user['nom'],
        ':prenom' =&amp;gt; $user['prenom'],
        ':contact' =&amp;gt; $user['contact'],
        ':password' =&amp;gt; $user['password'],
        ':jour' =&amp;gt; $user['jour'],
        ':mois' =&amp;gt; $user['mois'],
        ':annee' =&amp;gt; $user['annee'],
        ':genre' =&amp;gt; $user['genre']
    ]);

    unset($_SESSION['temp_user']);

    header("Location: succes.php");
    exit();

} else {

    header("Location: confirm.php");
    exit();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
?&amp;gt;`&lt;br&gt;
This project helped me understand how authentication systems work using PHP and MySQL.&lt;br&gt;&lt;br&gt;
I learned how to create a registration and login system similar to real applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Source Code
&lt;/h2&gt;

&lt;p&gt;You can find the full project on GitHub here: &lt;br&gt;
&lt;a href="https://github.com/Nouhailasemoud/login-system-php" rel="noopener noreferrer"&gt;https://github.com/Nouhailasemoud/login-system-php&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>security</category>
      <category>showdev</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
