Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
EtahLarry authored Jun 14, 2024
1 parent 09413e1 commit e9e53e5
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 85 deletions.
174 changes: 101 additions & 73 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,84 +1,112 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<!-- ===== CSS ===== -->
<link rel="stylesheet" href="assets/css/styles.css">
<!-- ===== CSS ===== -->
<link rel="stylesheet" href="assets/css/styles.css">

<!-- ===== BOX ICONS ===== -->
<link href='https://cdn.jsdelivr.net/npm/[email protected]/css/boxicons.min.css' rel='stylesheet'>

<title>Responsive Login Form Sign In Sign Up</title>
</head>
<body>
<div class="login">
<div class="login__content">
<div class="login__img">
<img src="assets/img/search.jpg" alt="">
</div>

<div class="login__forms">
<form action="" class="login__registre" id="login-in">
<h1 class="login__title">Sign In</h1>

<div class="login__box">
<i class='bx bx-user login__icon'></i>
<input type="text" placeholder="Username" class="login__input">
</div>

<div class="login__box">
<i class='bx bx-lock-alt login__icon'></i>
<input type="password" placeholder="Password" class="login__input">
</div>
<!-- ===== BOX ICONS ===== -->
<link href='https://cdn.jsdelivr.net/npm/[email protected]/css/boxicons.min.css' rel='stylesheet'>

<a href="#" class="login__forgot">Forgot password?</a>
<title>Responsive Login Form Sign In Sign Up</title>
</head>
<body>
<div class="login">
<div class="login__content">
<div class="login__img">
<img src="assets/img/search.jpg" alt="">
</div>

<a href="homepage.html" class="login__button">Sign In</a>
<div class="login__forms">
<!-- Sign In Form -->
<form action="login.php" method="POST" class="login__registre" id="login-in">
<h1 class="login__title">Sign In</h1>

<div>
<span class="login__account">Don't have an Account ?</span>
<span class="login__signin" id="sign-up">Sign Up</span>
</div>
</form>
<div class="login__box">
<i class='bx bx-user login__icon'></i>
<input type="text" name="username" placeholder="Username" class="login__input" required>
</div>

<form action="" class="login__create none" id="login-up">
<h1 class="login__title">Create Account</h1>

<div class="login__box">
<i class='bx bx-user login__icon'></i>
<input type="text" placeholder="Username" class="login__input">
</div>

<div class="login__box">
<i class='bx bx-at login__icon'></i>
<input type="text" placeholder="Email" class="login__input">
</div>

<div class="login__box">
<i class='bx bx-lock-alt login__icon'></i>
<input type="password" placeholder="Password" class="login__input">
</div>

<a href="homepage.html" class="login__button">Sign Up</a>

<div>
<span class="login__account">Already have an Account ?</span>
<span class="login__signup" id="sign-in">Sign In</span>
</div>

<div class="login__social">
<a href="#" class="login__social-icon"><i class='bx bxl-facebook' ></i></a>
<a href="#" class="login__social-icon"><i class='bx bxl-twitter' ></i></a>
<a href="#" class="login__social-icon"><i class='bx bxl-google' ></i></a>
</div>
</form>
</div>
<div class="login__box">
<i class='bx bx-lock-alt login__icon'></i>
<input type="password" name="password" placeholder="Password" class="login__input" required>
</div>

<a href="#" class="login__forgot">Forgot password?</a>

<button type="submit" class="login__button">Sign In</button>

<div>
<span class="login__account">Don't have an Account?</span>
<span class="login__signin" id="sign-up">Sign Up</span>
</div>
</form>

<!-- Sign Up Form -->
<form action="register.php" method="POST" class="login__create none" id="login-up">
<h1 class="login__title">Create Account</h1>

<div class="login__box">
<i class='bx bx-user login__icon'></i>
<input type="text" name="username" placeholder="Username" class="login__input" required>
</div>

<div class="login__box">
<i class='bx bx-at login__icon'></i>
<input type="email" name="email" placeholder="Email" class="login__input" required>
</div>

<div class="login__box">
<i class='bx bx-lock-alt login__icon'></i>
<input type="password" name="password" placeholder="Password" class="login__input" required>
</div>

<button type="submit" class="login__button">Sign Up</button>

<div>
<span class="login__account">Already have an Account?</span>
<span class="login__signup" id="sign-in">Sign In</span>
</div>

<div class="login__social">
<a href="#" class="login__social-icon"><i class='bx bxl-facebook'></i></a>
<a href="#" class="login__social-icon"><i class='bx bxl-twitter'></i></a>
<a href="#" class="login__social-icon"><i class='bx bxl-google'></i></a>
</div>
</form>
</div>
</div>
</div>

<!--===== MAIN JS =====-->
<script>
/*===== LOGIN SHOW and HIDDEN =====*/
const signUp = document.getElementById('sign-up'),
signIn = document.getElementById('sign-in'),
loginIn = document.getElementById('login-in'),
loginUp = document.getElementById('login-up');

signUp.addEventListener('click', () => {
// Remove classes first if they exist
loginIn.classList.remove('block');
loginUp.classList.remove('none');

// Add classes
loginIn.classList.toggle('none');
loginUp.classList.toggle('block');
});

signIn.addEventListener('click', () => {
// Remove classes first if they exist
loginIn.classList.remove('none');
loginUp.classList.remove('block');

<!--===== MAIN JS =====-->
<script src="assets/js/main.js"></script>
</body>
</html>
// Add classes
loginIn.classList.toggle('block');
loginUp.classList.toggle('none');
});
</script>
</body>
</html>
42 changes: 35 additions & 7 deletions login.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,57 @@
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form data
$username = $_POST['username'];
$password = $_POST['password'];

// Validate form data
if (empty($username) || empty($password)) {
die('Please fill all required fields.');
}

// Connect to the database
$conn = new mysqli('localhost', 'root', '', 'user_database');

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM users WHERE username='$username'";
$result = $conn->query($sql);
// Prepare the SQL statement
$sql = "SELECT * FROM users WHERE username = ?";
$stmt = $conn->prepare($sql);

if ($stmt === false) {
die('Prepare failed: ' . $conn->error);
}

// Bind parameters
$stmt->bind_param("s", $username);

// Execute the statement
$stmt->execute();
$result = $stmt->get_result();

// Check if user exists
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
if (password_verify($password, $row['password'])) {
echo "Login successful";
$user = $result->fetch_assoc();

// Verify password
if (password_verify($password, $user['password'])) {
// Redirect to homepage or dashboard
header("Location: homepage.html");
exit();
} else {
echo "Invalid password";
die('Invalid password.');
}
} else {
echo "No user found";
die('User not found.');
}

// Close the statement and connection
$stmt->close();
$conn->close();
} else {
die('Invalid request method.');
}
?>
36 changes: 31 additions & 5 deletions register.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form data
$username = $_POST['username'];
$email = $_POST['email'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$password = $_POST['password'];

// Validate form data
if (empty($username) || empty($email) || empty($password)) {
die('Please fill all required fields.');
}

// Hash the password
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

// Connect to the database
$conn = new mysqli('localhost', 'root', '', 'user_database');

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$password')";
// Prepare the SQL statement
$sql = "INSERT INTO users (username, email, password) VALUES (?, ?, ?)";
$stmt = $conn->prepare($sql);

if ($stmt === false) {
die('Prepare failed: ' . $conn->error);
}

// Bind parameters
$stmt->bind_param("sss", $username, $email, $hashed_password);

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
// Execute the statement
if ($stmt->execute()) {
// Redirect to homepage or login page
header("Location: homepage.html");
exit();
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
die('Execute failed: ' . $stmt->error);
}

// Close the statement and connection
$stmt->close();
$conn->close();
} else {
die('Invalid request method.');
}
?>
9 changes: 9 additions & 0 deletions test_connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
$conn = new mysqli('localhost', 'root', '', 'user_database');

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$conn->close();
?>

0 comments on commit e9e53e5

Please sign in to comment.