User Authentication System
User Authentication System
User Authentication System
Overview:
This project implements a simple user authentication system where users can sign up, log in, and
access protected routes after logging in. It uses Node.js and Express.js to handle server-side logic,
SQL to store user credentials, and JavaScript for client-side validation and interactions.
Technologies:
Steps:
npm init -y
app.use(bodyParser.json());
// Database connection
const db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'auth_db'
});
db.connect((err) => {
});
const sql = 'INSERT INTO users (username, password) VALUES (?, ?)';
});
});
// Login users
});
});
// Protected route
});
});
app.listen(3000, () => {
});
USE auth_db;
);
<!DOCTYPE html>
<html>
<head>
<title>User Authentication</title>
</head>
<body>
<h2>Register</h2>
<button onclick="register()">Register</button>
<h2>Login</h2>
<button onclick="login()">Login</button>
<h2>Dashboard</h2>
<script>
method: 'POST',
});
alert(data);
method: 'POST',
});
localStorage.setItem('token', data.token);
alert('Login successful');
alert(data);
</script>
</body>
</html>
node auth.js
Open the browser and visit http://localhost:3000 to interact with the user authentication system.