Professional Documents
Culture Documents
ST Complete Code
ST Complete Code
ST Complete Code
Use appropriate hashing algorithms like bcrypt or Argon2 for storing passwords securely.
Apply salting techniques to further enhance password security.
1
Step 9: Testing and Debugging
Test the website's functionality, including user registration, login, and account management.
Debug any issues or errors encountered during testing.
2
E-commerce electronic website using HTML, CSS, and PHP that incorporates a MySQL
database for a login account system with user-specific content display and registration
functionality.
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<form method="post" action="login.php">
<h2>Login</h2>
<label for="username">Username:</label>
<input type="text" name="username" required>
<label for="password">Password:</label>
<input type="password" name="password" required>
<input type="submit" value="Login">
</form>
<p>Don't have an account? <a href="register.html">Register here</a></p>
</div>
</body>
</html>
h2 {
text-align: center;
}
3
label, input {
display: block;
margin-bottom: 10px;
}
input[type="submit"] {
margin-top: 10px;
background-color: #4CAF50;
color: white;
border: none;
padding: 10px;
cursor: pointer;
}
// Database connection
$host = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database_name";
// User authentication
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = mysqli_real_escape_string($conn, $_POST["username"]);
$password = mysqli_real_escape_string($conn, $_POST["password"]);
if (mysqli_num_rows($result) == 1) {
$row = mysqli_fetch_assoc($result);
if (password_verify($password, $row["password"])) {
$_SESSION["username"] = $username;
header("Location: dashboard.php");
} else {
echo "Invalid password";
}
} else {
echo "Invalid username";
}
}
mysqli_close($conn);
?>
4
HTML code (register.html):
<!DOCTYPE html>
<html>
<head>
<title>Registration Page</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<form method="post" action="register.php">
<h2>Register</h2>
<label for="username">Username:</label>
<input type="text" name="username" required>
<label for="password">Password:</label>
<input type="password" name="password" required>
<input type="submit" value="Register">
</form>
</div>
</body>
</html>
// User registration
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = mysqli_real_escape_string($conn, $_POST["username"]);
$password = mysqli_real_escape_string($conn, $_POST["password"]);
// Validate input
5
$sql = "INSERT INTO users (username, password) VALUES ('$username',
'$hashedPassword')";
if (mysqli_query($conn, $sql)) {
echo "Registration successful.";
} else {
echo "Error: " . mysqli_error($conn);
}
}
}
mysqli_close($conn);
?>
PHP code (dashboard.php):
<?php
session_start();
// Additional content and functionality specific to the logged-in user can be added
here
?>