DBMS Report

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

A

Micro-Project
On

Login System
Submitted To
MSBTE
In Partial Fulfilment of Requirement of Diploma Of
Computer Engineering
Under I Scheme
Submitted By

Mr. Kunal Masurkar


Mr. Aryan Shirodkar
Mr. Prasanna Kadrekar
Mr. Govind Gawade

Under the Guidance Of

Mr. Prashant Kate

FOR ACADEMIC YEAR 2021-2022

YASHWANTRAO BHAONSALE POLYTECHNIC,

SAWANTWADI.

1
MAHARASHTRA STATE BOARD OF
TECHNICAL EDUCATION

CERTIFICATE

This is to certify that,


Mr. Kunal Vijay Masurkar Roll No.06
Mr. Govind Gurunath Gawade Roll No.12
Mr. Prasanna Prasad Kadrekar Roll No.13
Mr. Aryan Sunil Shirodkar Roll No.17

Of Third semester of diploma in COMPUTER ENGINEERING of institute Yashwantrao


Bhonsale Polytechnic (1742) has completed the Micro Project satisfactorily in subject
Database Management System (22319) for the academic year 2021 to 2022 as prescribed in
the curriculum.

Subject Faculty HOD Principal

Seal of

Institution

2
INDEX

Sr. Contains Page


No. No.
1. Abstract 4
2. Introduction 5
3. Project Explanation 6
4. Project Requirements 7
5. PHP MySQL Login System 8
6. Building Logic System 12
7. Outputs 17
8. Conclusion 20
9. References 21

3
Abstract
A Database Management System (DBMS) is a set of computer programs that controls the creation, maintenance,
and the use of a database. It allows organizations to place control of database development in the hands of
database administrators (DBAs) and other specialists. A DBMS is a system software package that helps the use
of integrated collection of data records and files known as databases. It allows different user application
programs to easily access the same database. DBMSs may use any of a variety of database models, such as the
network model or relational model. In large systems, a DBMS allows users and other software to store and
retrieve data in a structured way. Instead of having to write computer programs to extract information, user can
ask simple questions in a query language. Thus, many DBMS packages provide Fourth-generation programming
language (4GLs) and other application development features. It helps to specify the logical organization for a
database and access and use the information within a database. It provides facilities for controlling data access,
enforcing data integrity, managing concurrency, and restoring the database from backups. A DBMS also
provides the ability to logically present database information to users.

4
Introduction
A login page is a web page or an entry page to a website that requires user identification and authentication,
regularly performed by entering a username and password combination. Logins may provide access to an entire
site or part of a website. Logging in not only provides site access for the user, but also allows the website to
track user actions and behavior. Logging off a webpage or site may be manual by the user or they can occur
automatically when certain conditions (such as closing the page, turning off the computer, a long time delay,
etc.) occur.

Some websites use cookies to track users during their logged in sessions. Generally, these cookies will turn off
when the user logs out. Those cookies that are automatically deactivated and deleted from the user’s computer
are called session-only cookies. Protective measures that delete and invalidate associations between a user’s
handle and the session help assure users that logins can happen from any location, including public computers.

5
Project Explanation
A login page is a door that users must open in order to get the best out of their user experience with a
website.
It is the starting point of navigating a website in a personalized manner. By creating an account on a
website, you get to customize some aspects of your experience with the site and get access to
membership benefits.
Well-designed website login pages should inspire a sense of security. A poor login page will
immediately influence your conversion rate because people are not going to sign up in the first place.
Designing a website login page properly is a condition of owning a website, considering that this page
is most likely to be accessed by users at least once per browsing session. People who want to access
their accounts can’t do it without reaching the login page, and if the login screen is not designed
properly and it’s a pain to use, you’ll lose users.

6
The Requirements:
❖ We should have knowledge of HTML, CSS, PHP and MySQL for creating the login system.
❖ Text Editor - For writing the code. We can use any text editor such as Notepad, Notepad++,
Dreamweaver, etc.
❖ XAMPP - XAMPP is a cross-platform software, which stands for Cross-platform(X) Apache server (A),
MySQL (M), PHP (P), Perl (P). XAMPP is a complete software package, so, we don't need to install all
these separately.

7
PHP MySQL Login System
Step 1: Creating the Database Table
CREATE TABLE users (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

Step 2: Creating the Config File


<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'demo');

$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

if($link === false){


die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>

8
Step 3: Creating the Registration Form

<?php

require_once "config.php";

$username = $password = $confirm_password = "";


$username_err = $password_err = $confirm_password_err = "";

if($_SERVER["REQUEST_METHOD"] == "POST"){

if(empty(trim($_POST["username"]))){
$username_err = "Please enter a username.";
} elseif(!preg_match('/^[a-zA-Z0-9_]+$/', trim($_POST["username"]))){
$username_err = "Username can only contain letters, numbers, and
underscores.";
} else{
$sql = "SELECT id FROM users WHERE username = ?";

if($stmt = mysqli_prepare($link, $sql)){

mysqli_stmt_bind_param($stmt, "s", $param_username);

$param_username = trim($_POST["username"]);

if(mysqli_stmt_execute($stmt)){

mysqli_stmt_store_result($stmt);

if(mysqli_stmt_num_rows($stmt) == 1){
$username_err = "This username is already taken.";
} else{
$username = trim($_POST["username"]);
}
} else{
echo "Oops! Something went wrong. Please try again
later.";
}

mysqli_stmt_close($stmt);
}
}

if(empty(trim($_POST["password"]))){
$password_err = "Please enter a password.";
} elseif(strlen(trim($_POST["password"])) < 6){
$password_err = "Password must have atleast 6 characters.";
} else{
$password = trim($_POST["password"]);
}

9
if(empty(trim($_POST["confirm_password"]))){
$confirm_password_err = "Please confirm password.";
} else{
$confirm_password = trim($_POST["confirm_password"]);
if(empty($password_err) && ($password != $confirm_password)){
$confirm_password_err = "Password did not match.";
}
}

if(empty($username_err) && empty($password_err) &&


empty($confirm_password_err)){

$sql = "INSERT INTO users (username, password) VALUES (?, ?)";

if($stmt = mysqli_prepare($link, $sql)){

mysqli_stmt_bind_param($stmt, "ss", $param_username,


$param_password);

$param_username = $username;
$param_password = password_hash($password, PASSWORD_DEFAULT);

if(mysqli_stmt_execute($stmt)){

header("location: login.php");
} else{
echo "Oops! Something went wrong. Please try again
later.";
}

mysqli_stmt_close($stmt);
}
}

mysqli_close($link);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sign Up</title>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min
.css">
<style>
body{ font: 14px sans-serif; }
.wrapper{ width: 360px; padding: 20px; }
</style>
10
</head>
<body>
<div class="wrapper">
<h2>Sign Up</h2>
<p>Please fill this form to create an account.</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);
?>" method="post">
<div class="form-group">
<label>Username</label>
<input type="text" name="username" class="form-control
<?php echo (!empty($username_err)) ? 'is-invalid' : ''; ?>" value="<?php
echo $username; ?>">
<span class="invalid-feedback"><?php echo $username_err;
?></span>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control
<?php echo (!empty($password_err)) ? 'is-invalid' : ''; ?>" value="<?php
echo $password; ?>">
<span class="invalid-feedback"><?php echo $password_err;
?></span>
</div>
<div class="form-group">
<label>Confirm Password</label>
<input type="password" name="confirm_password"
class="form-control <?php echo (!empty($confirm_password_err)) ? 'is-
invalid' : ''; ?>" value="<?php echo $confirm_password; ?>">
<span class="invalid-feedback"><?php echo
$confirm_password_err; ?></span>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary"
value="Submit">
<input type="reset" class="btn btn-secondary ml-2"
value="Reset">
</div>
<p>Already have an account? <a href="login.php">Login
here</a>.</p>
</form>
</div>
</body>
</html>

11
Building the Login System
Step 1: Creating the Login Form

<?php
session_start();

if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){


header("location: welcome.php");
exit;
}

require_once "config.php";

$username = $password = "";


$username_err = $password_err = $login_err = "";

if($_SERVER["REQUEST_METHOD"] == "POST"){

if(empty(trim($_POST["username"]))){
$username_err = "Please enter username.";
} else{
$username = trim($_POST["username"]);
}

if(empty(trim($_POST["password"]))){
$password_err = "Please enter your password.";
} else{
$password = trim($_POST["password"]);
}

if(empty($username_err) && empty($password_err)){

$sql = "SELECT id, username, password FROM users WHERE username =


?";

if($stmt = mysqli_prepare($link, $sql)){

mysqli_stmt_bind_param($stmt, "s", $param_username);

$param_username = $username;

if(mysqli_stmt_execute($stmt)){

mysqli_stmt_store_result($stmt);

if(mysqli_stmt_num_rows($stmt) == 1){
// Bind result variables
12
mysqli_stmt_bind_result($stmt, $id, $username,
$hashed_password);
if(mysqli_stmt_fetch($stmt)){
if(password_verify($password, $hashed_password)){

session_start();

$_SESSION["loggedin"] = true;
$_SESSION["id"] = $id;
$_SESSION["username"] = $username;

header("location: welcome.php");
} else{
$login_err = "Invalid username or password.";
}
}
} else{
$login_err = "Invalid username or password.";
}
} else{
echo "Oops! Something went wrong. Please try again
later.";
}

mysqli_stmt_close($stmt);
}
}
mysqli_close($link);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min
.css">
<style>
body{ font: 14px sans-serif; }
.wrapper{ width: 360px; padding: 20px; }
</style>
</head>
<body>
<div class="wrapper">
<h2>Login</h2>
<p>Please fill in your credentials to login.</p>

<?php
13
if(!empty($login_err)){
echo '<div class="alert alert-danger">' . $login_err .
'</div>';
}
?>

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);


?>" method="post">
<div class="form-group">
<label>Username</label>
<input type="text" name="username" class="form-control
<?php echo (!empty($username_err)) ? 'is-invalid' : ''; ?>" value="<?php
echo $username; ?>">
<span class="invalid-feedback"><?php echo $username_err;
?></span>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control
<?php echo (!empty($password_err)) ? 'is-invalid' : ''; ?>">
<span class="invalid-feedback"><?php echo $password_err;
?></span>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary"
value="Login">
</div>
<p>Don't have an account? <a href="register.php">Sign up
now</a>.</p>
</form>
</div>
</body>
</html>

14
Step 2: Creating the Welcome Page

<?php
session_start();

if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){


header("location: login.php");
exit;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Welcome</title>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min
.css">
<style>
body{ font: 14px sans-serif; text-align: center; }
</style>
</head>
<body>
<h1 class="my-5">Hi, <b><?php echo
htmlspecialchars($_SESSION["username"]); ?></b>. Welcome to our site.</h1>
<p>
<a href="reset-password.php" class="btn btn-warning">Reset Your
Password</a>
<a href="logout.php" class="btn btn-danger ml-3">Sign Out of Your
Account</a>
</p>
</body>
</html>

15
Step 3: Creating the Logout Script

<?php
session_start();

$_SESSION = array();

session_destroy();

header("location: login.php");
exit;
?>

Adding the Password Reset Feature


<?php
session_start();

if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){


header("location: login.php");
exit;
}

require_once "config.php";

16
OUTPUTS:

1.Register Page:

17
2.Login Page:

2.Home Page:

18
3.Reset Password Page:

4.Database (Table):

19
Conclusions:
In conclusion. Database implementation plan is essential for any organization that once to boost is sales or
increase their customers experience, a good database implementation plan we supposed to have, all the factors
and the significance value towards the organization, not forgetting the requirements that are needed. In my
opinion, I could have recommended using a computerized, database management system. This is because it is
faster to implement and also it requires less amount of time and finance to set up, the future of database lies on
the power of the organization .and the funds that they can be able to set aside to implement new database
management system.

20
Reference:
1. https://www.c-sharpcorner.com/UploadFile/9582c9/script-for-login-logout-and-view-
using-php-mysql-and-boots/

2. https://www.tutorialrepublic.com/php-tutorial/php-mysql-login-system.php

3. https://www.javatpoint.com/php-mysql-login-system

4. https://wpamelia.com/login-page-design/

21

You might also like