Using only HTML-WPS Office
Using only HTML-WPS Office
for real-world applications, as JavaScript cannot directly communicate with databases (like MySQL)
without a server-side language like PHP, Python, or Node.js. However, for educational purposes or
testing, you can use local storage or indexedDB (a browser-based database) as an alternative.
Below, I'll show you how to create a mock database with JavaScript using localStorage. This will simulate
a simple signup and login system.
---
HTML (index.html)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Degree - Connect</title>
</head>
<body>
<header>
<h1>Degree</h1>
</header>
<main>
<section id="signup">
<h2>Create an Account</h2>
<form id="signupForm">
<label for="username">Username:</label>
<label for="email">Email:</label>
<label for="password">Password:</label>
</form>
</section>
<section id="login">
<h2>Login</h2>
<form id="loginForm">
<label for="loginEmail">Email:</label>
<button type="submit">Login</button>
</form>
</section>
</main>
<script src="script.js"></script>
</body>
</html>
---
CSS (styles.css)
/* General Styles */
body {
margin: 0;
padding: 0;
background: #f0f2f5;
color: #333;
text-align: center;
header {
background: #4267B2;
color: white;
padding: 1rem 0;
main {
width: 80%;
max-width: 500px;
form {
background: white;
padding: 1.5rem;
margin: 1rem 0;
border-radius: 10px;
form label {
display: block;
margin-top: 10px;
font-weight: bold;
form input {
width: 100%;
padding: 0.5rem;
margin-top: 5px;
margin-bottom: 15px;
border-radius: 5px;
form button {
width: 100%;
padding: 0.7rem;
background: #4267B2;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
form button:hover {
background: #365899;
}
---
JavaScript (script.js)
localStorage.setItem('users', JSON.stringify(users));
return users.find(user => user.email === email && user.password === password);
// Handle Signup
e.preventDefault();
e.target.reset();
});
// Handle Login
e.preventDefault();
if (user) {
} else {
});
---
How It Works
1. Signup Process:
The saveUser function adds the user to the browser's localStorage, which acts as a mock database.
Passwords are stored in plain text here (not secure but sufficient for learning purposes).
2. Login Process:
The findUser function checks if the email and password match any user in localStorage.
3. LocalStorage:
Data is stored in the browser. Open developer tools (F12 → Application tab → Local Storage) to view the
data.
---
Limitations
1. Security:
Passwords are not encrypted. For real applications, you need backend hashing (e.g., bcrypt).
2. Scalability:
3. No Server Communication:
This setup is entirely client-side and cannot support features like sharing data between users.
---
When to Use
Educational projects.
For real-world applications, you'll need to use a proper backend and database. Let me know if you'd like
guidance on that!