Login & Signup System with HTML, CSS & JavaScript

30 DAYS 30 PROJECT CHALLENGE

Day #01

Project Overview

A modern Login & Signup System built using HTML, CSS, and JavaScript, focusing on clean UI design and client-side form validation.
The project allows users to create an account and securely log in using stored credentials. It demonstrates form handling, input validation, password visibility toggling, and basic authentication logic using LocalStorage, making it ideal for beginners learning real-world frontend concepts.

Key Features

  • User-friendly Login and Signup forms with smooth toggle functionality.
  • Client-side validation for name, email format, and password length.
  • Prevents login without prior signup.
  • Stores user credentials securely in LocalStorage (frontend demo).
  • Show/Hide password option for better usability.
  • Displays clear error and success messages.
  • Responsive layout suitable for mobile, tablet, and desktop devices.
  • Clean and accessible UI with proper form labels and feedback.

HTML Code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Login & Signup System</title>
  <link rel="stylesheet" href="style.css" />
</head>
<body>

  <div class="container">
    <h2 id="formTitle">Login</h2>

    <form id="authForm">

      <div class="input-group" id="nameGroup">
        <label>Full Name</label>
        <input type="text" id="name" />
        <div class="error" id="nameError">Name is required</div>
      </div>

      <div class="input-group">
        <label>Email</label>
        <input type="email" id="email" />
        <div class="error" id="emailError">Enter a valid email</div>
      </div>

      <div class="input-group">
        <label>Password</label>
        <input type="password" id="password" />
        <span class="password-toggle" onclick="togglePassword()">Show Password</span>
        <div class="error" id="passwordError">
          Password must be at least 6 characters
        </div>
      </div>

      <button type="submit" id="submitBtn">Login</button>

      <div class="success" id="successMsg"></div>
    </form>

    <div class="toggle">
      <span id="toggleText">Don't have an account?</span>
      <span class="toggle-link" id="toggleLink" onclick="toggleForm()">Sign Up</span>
    </div>
  </div>

  <script src="script.js"></script>
</body>
</html>

CSS Code

* {
  box-sizing: border-box;
  font-family: "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #042453;
}

.container {
  background: #ffffff;
  width: 380px;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

h2 {
  text-align: center;
  margin-bottom: 20px;
}

.input-group {
  margin-bottom: 15px;
}

.input-group label {
  display: block;
  font-size: 14px;
  margin-bottom: 5px;
}

.input-group input {
  width: 100%;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #ccc;
  outline: none;
}

.input-group input:focus {
  border-color: #6366f1;
}

.error {
  color: red;
  font-size: 12px;
  margin-top: 5px;
  display: none;
}

button {
  width: 100%;
  padding: 12px;
  background: #042453;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
}

button:hover {
  background: #4338ca;
}

.toggle {
  text-align: center;
  margin-top: 15px;
  font-size: 14px;
}

.toggle-link {
  color: #4f46e5;
  cursor: pointer;
  font-weight: bold;
  margin-left: 5px;
}

.success {
  text-align: center;
  color: green;
  margin-top: 10px;
  display: none;
}

.password-toggle {
  font-size: 12px;
  color: #4f46e5;
  cursor: pointer;
  margin-top: 5px;
  display: inline-block;
}

#nameGroup {
  display: none;
}

Javascript Code

const formTitle = document.getElementById("formTitle");
const nameGroup = document.getElementById("nameGroup");
const submitBtn = document.getElementById("submitBtn");
const toggleText = document.getElementById("toggleText");
const toggleLink = document.getElementById("toggleLink");

const form = document.getElementById("authForm");
const successMsg = document.getElementById("successMsg");

let isSignup = false;

/* ---------------- TOGGLE FORM ---------------- */
function toggleForm() {
  isSignup = !isSignup;

  if (isSignup) {
    formTitle.innerText = "Sign Up";
    submitBtn.innerText = "Sign Up";
    toggleText.innerText = "Already have an account?";
    toggleLink.innerText = "Login";
    nameGroup.style.display = "block";
  } else {
    formTitle.innerText = "Login";
    submitBtn.innerText = "Login";
    toggleText.innerText = "Don't have an account?";
    toggleLink.innerText = "Sign Up";
    nameGroup.style.display = "none";
  }

  clearErrors();
  successMsg.style.display = "none";
  form.reset();
}

/* ---------------- SHOW / HIDE PASSWORD ---------------- */
function togglePassword() {
  const password = document.getElementById("password");
  password.type = password.type === "password" ? "text" : "password";
}

/* ---------------- CLEAR ERRORS ---------------- */
function clearErrors() {
  document.querySelectorAll(".error").forEach(err => {
    err.style.display = "none";
  });
}

/* ---------------- FORM SUBMIT ---------------- */
form.addEventListener("submit", function (e) {
  e.preventDefault();
  clearErrors();

  const name = document.getElementById("name").value.trim();
  const email = document.getElementById("email").value.trim();
  const password = document.getElementById("password").value.trim();

  let isValid = true;

  if (isSignup && name === "") {
    document.getElementById("nameError").style.display = "block";
    isValid = false;
  }

  if (!email.includes("@") || email === "") {
    document.getElementById("emailError").style.display = "block";
    isValid = false;
  }

  if (password.length < 6) {
    document.getElementById("passwordError").style.display = "block";
    isValid = false;
  }

  if (!isValid) return;

  /* -------- SIGN UP LOGIC -------- */
  if (isSignup) {
    const user = { name, email, password };
    localStorage.setItem("user", JSON.stringify(user));

    successMsg.style.display = "block";
    successMsg.innerText = "Signup successful 🎉 Please login now.";

    toggleForm(); // Switch to login
    return;
  }

  /* -------- LOGIN LOGIC -------- */
  const savedUser = JSON.parse(localStorage.getItem("user"));

  if (!savedUser) {
    alert("No account found. Please sign up first.");
    return;
  }

  if (email === savedUser.email && password === savedUser.password) {
    successMsg.style.display = "block";
    successMsg.innerText = `Welcome back, ${savedUser.name} ✅`;
    form.reset();
  } else {
    alert("Invalid email or password ❌");
  }
});
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Projects

Day 2 : Multi-Step Form 

A step-by-step form with progress tracking and input validation.

Concepts: DOM manipulation, form validation, progress tracking.

Day 3 : OTP Verification UI

Generates an OTP shown via alert and verifies it through a popup-based input UI.

Concepts: DOM manipulation, modal UI, random OTP generation, input handling.

Day 4 : Search Autocomplete Feature

Displays real-time search suggestions with keyboard navigation and highlighted matches.

Concepts: DOM manipulation, debounce, keyboard events, array filtering.