From 3db6af498b0a4a8737232b7e94c94b87dae6ff88 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 15 Nov 2025 23:25:15 +0000 Subject: [PATCH] 1 --- db/migrate.php | 21 +++++++ db/migrations/001_create_users_table.sql | 6 ++ index.php | 78 ++++++++---------------- login.php | 69 +++++++++++++++++++++ signup.php | 74 ++++++++++++++++++++++ 5 files changed, 195 insertions(+), 53 deletions(-) create mode 100644 db/migrate.php create mode 100644 db/migrations/001_create_users_table.sql create mode 100644 login.php create mode 100644 signup.php diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..06aba1c --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,21 @@ +exec($sql); + echo "Migration '001_create_users_table.sql' applied successfully.\n"; + } else { + echo "Migration file not found.\n"; + } + } catch (PDOException $e) { + die("Migration failed: " . $e->getMessage() . "\n"); + } +} + +run_migrations(); + diff --git a/db/migrations/001_create_users_table.sql b/db/migrations/001_create_users_table.sql new file mode 100644 index 0000000..6f18a32 --- /dev/null +++ b/db/migrations/001_create_users_table.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(50) NOT NULL UNIQUE, + password_hash VARCHAR(255) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/index.php b/index.php index 3b62c11..ea35e73 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,12 @@ + @@ -45,37 +54,9 @@
- -
- Jane Doe -
-
- Jane Doe - 10:42 AM -
-

Sounds good! See you then.

-
-
- -
- John Smith -
-
- John Smith - Yesterday -
-

Can you send me the report?

-
-
-
- Project Team -
-
- Project Team - 3/15/25 -
-

Alex: Don't forget the meeting...

-
+
+ +

No conversations yet.

@@ -84,35 +65,26 @@
- Jane Doe -
-
Jane Doe
-

Online

+
+ Avatar +
+
Select a Conversation
+

Offline

+
- - - + + +
-
-
Hey! Are we still on for lunch tomorrow?
-
10:40 AM
-
-
-
Hi! Yes, absolutely. I'm looking forward to it.
-
10:41 AM
-
-
-
Great! How about 1 PM at the usual place?
-
10:41 AM
-
-
-
Sounds good! See you then.
-
10:42 AM
+
+ +

Welcome to Message NOW

+

Select a conversation to start messaging.

diff --git a/login.php b/login.php new file mode 100644 index 0000000..132a619 --- /dev/null +++ b/login.php @@ -0,0 +1,69 @@ +prepare('SELECT id, username, password_hash FROM users WHERE username = ?'); + $stmt->execute([$username]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['password_hash'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['username'] = $user['username']; + header('Location: index.php'); + exit; + } else { + $error = 'Invalid username or password.'; + } + } catch (PDOException $e) { + $error = 'Database error: ' . $e->getMessage(); + } + } +} +?> + + + + + + Login + + + + +
+
+
+

Login

+ +
+ +
+
+ + +
+
+ + +
+ +
+
+

Don't have an account? Sign Up

+
+
+
+
+ + diff --git a/signup.php b/signup.php new file mode 100644 index 0000000..ed05876 --- /dev/null +++ b/signup.php @@ -0,0 +1,74 @@ +prepare('SELECT id FROM users WHERE username = ?'); + $stmt->execute([$username]); + if ($stmt->fetch()) { + $error = 'This username is already taken.'; + } else { + // Hash password and insert user + $password_hash = password_hash($password, PASSWORD_DEFAULT); + $stmt = $pdo->prepare('INSERT INTO users (username, password_hash) VALUES (?, ?)'); + $stmt->execute([$username, $password_hash]); + + // Log the user in and redirect + $_SESSION['user_id'] = $pdo->lastInsertId(); + $_SESSION['username'] = $username; + header('Location: index.php'); + exit; + } + } catch (PDOException $e) { + $error = 'Database error: ' . $e->getMessage(); + } + } +} +?> + + + + + + Sign Up + + + + +
+
+
+

Create Account

+ +
+ +
+
+ + +
+
+ + +
+ +
+
+

Already have an account? Log In

+
+
+
+
+ +