This repository contains a simple PHP-based login and registration system with password recovery functionality. It uses a MySQL database to store user information. The system consists of the following components:
config.php
: This file contains the database connection settings using themysqli
extension.
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'crud');
$db = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
index.php
: The main login page that allows users to log in.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Head section content -->
</head>
<body>
<!-- Login form content -->
</body>
</html>
login.php
: Handles the user login process and redirects accordingly.
<?php
include("config.php");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Login logic
}
?>
register.php
: Provides a registration form for new users.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Head section content -->
</head>
<body>
<!-- Registration form content -->
</body>
</html>
insert.php
: Handles user registration and inserts new user data into the database.
<?php
include "config.php";
if (isset($_POST['users'])) {
// Registration logic
}
?>
update.php
: Allows users to update their password after logging in.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Head section content -->
</head>
<body>
<!-- Update password form content -->
</body>
</html>
updatepwd.php
: Handles the password update process.
<?php
include("config.php");
if (isset($_POST['users'])) {
// Update password logic
}
?>
- Set up a MySQL database and configure
config.php
with your database details. - Host the PHP files on a server with PHP and MySQL support.
- Access
index.php
to log in orregister.php
to create a new account. - Use
update.php
to update your password andupdatepwd.php
for the update process.
Remember to ensure proper security measures, such as input validation and password hashing, before deploying this system in a production environment.
The system uses a MySQL database named crud. It includes a table named users with the following structure:
id: Primary key (auto-increment) Other columns: (These would be based on your implementation) Please ensure proper security measures, such as input validation and password hashing, before deploying this system in a production environment.
We've added a new feature to the PHP login and registration system that allows administrators to delete user accounts. This feature is useful for managing user accounts in scenarios where account removal is required.
-
Backend Logic:
The new feature is implemented in the
deluser.php
file. When an administrator submits the delete user form, the provided email and password are checked against the database. If a match is found, the user account associated with the provided email is deleted from the database.<?php include ("config.php"); if($_SERVER['REQUEST_METHOD']=='POST') { $myusername = mysqli_real_escape_string($db, $_POST['email']); $mypassword = mysqli_real_escape_string($db, $_POST['pwd']); // Check if user exists and password matches $sql = "SELECT * FROM users WHERE email = '$myusername' and pwd = '$mypassword'"; $count = mysqli_num_rows(mysqli_query($db, $sql)); if ($count == 1) { // Delete the user account $delquery="DELETE FROM users WHERE email='$myusername'"; $delrun=mysqli_query($db,$delquery); if($delrun) { echo "<script>alert('User Deleted');window.location.href='register.php';</script>"; } } else { echo "<script>alert('Your Login Name or Password is invalid');window.location.href='deluser.php';</script>"; exit(); } } ?>
-
Frontend Form:
The user interface for this feature is provided through the
deluser.php
file. Administrators need to enter the email and password of the user they want to delete. Upon submission, the form data is sent to the server for processing.<!DOCTYPE html> <html lang="en"> <head> <!-- Head section content --> </head> <body> <!-- Delete user form content --> </body> </html>
- Open the
deluser.php
page from your browser. - Enter the email and password of the user you want to delete.
- Click the "Delete user" button.
- If the provided email and password match an existing user account, the account will be deleted and a confirmation message will be shown.
- If the provided information is incorrect, an error message will be displayed.
Please ensure that only authorized administrators have access to this feature to prevent misuse.