Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Allow the user to login. authenticate.php file database info CREATE TABLE users ( id int primary key auto_increment, username varchar(255), password varchar(255) ); -- insert

Allow the user to login.

authenticate.php file

// TODO: create a database connection $servername = "localhost"; $username = "root"; $password = ""; $dbname = "una_bball";

$conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $query = mysqli_query($conn, "SELECT password FROM users WHERE password = '$_REQUEST[userpass]'"); $row = mysqli_fetch_array($query); $row['password'];

// TODO: use the users table for authentication if ($_REQUEST['userpass'] === $row['password']) { $_SESSION['password'] = $_REQUEST['userpass']; $_SESSION['error'] = '';

} else { $_SESSION['error'] = 'invalid username or password'; } // TODO: create variables for the input form data // define variables and set to empty values $userpass = ''; $enduser= '';

// TODO: query the database for the input user's credentials $query = mysqli_query($conn, "SELECT username FROM users WHERE username = '$_REQUEST[enduser]'"); $row = mysqli_fetch_array($query); $row['username']; // TODO: authenticate the user using password_verify // if the input credentials are valid, put the user in the SESSION // (using the key "username") and clear the "error" in the session // otherwise, put "invalid username or password" in the session using // the "error" key

if (password_verify($_POST['userpass'],$row['password'])) { // echo 'Password is valid!'; $_SESSION['username'] = $_REQUEST['enduser']; $_SESSION['error'] = ''; } else { $_SESSION['error'] = 'invalid username or password'; } // TODO: close the database connection $conn->close();

header("location:index.php"); ?>

database info

CREATE TABLE users ( id int primary key auto_increment, username varchar(255), password varchar(255) );

-- insert a row into the users table for the administrator: -- username = admin -- password = pwd INSERT INTO users (username, password) VALUES ('admin', '$2y$10$6EagpQz90eekX4cIlXjWdu/iCCo3jmSPrLmm9kJ/OVzbmwHaJZGzG');

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Multidimensional Array Data Management In Databases

Authors: Florin Rusu

1st Edition

1638281483, 978-1638281481

More Books

Students also viewed these Databases questions