Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the login form Write a PHP file that will output a form containing 3 field

ID: 3903426 • Letter: W

Question

Write the login form

Write a PHP file that will output a form containing 3 fields: username, password and “Remember me!” checkbox. Upon submission of the form, the code should check against a table in MySQL. You may not store the password in original text (use mysql MD5 https://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html#function_md5). (Links to an external site.)Links to an external site. If the username/password pair is correct , display a welcome message and save a cookie that identifies the user to the server if the "Remember me!" checkbox is checked. On further visits to the page, the user should appear logged in, even if the browser has been closed and restarted; If not, display the message “Invalid username or password” followed by the same login form. The output should be one of following options:

The login form.

The invalid message and the login form, if failed login.

The welcome message containing a “Log Out” button, if successful login (the login form may contain the auto filled input user and password fields) .

When user clicks “Log out” button, remove the cookie so that the user is logged out. Clicking the button should redirect the user to the same page, which now shows a login form (which contains the empty input user and password fields).

'Remember me' should last at least a week.

Deploy it in your icoolshow.net in a folder called 'project'.

Please give me one pair of uid/password for me to test your project in your submission.

Here is the current code:

<?php
$host = 'localhost';
$username = 'icoolsho_sminutt@localhost';
$password = '';
$database = 'icoolsho_sminutti';
$db = new mysqli($host, $username, $password, $database);

$cookie_name = '';

if(isset($_COOKIE[$cookie_name]))
{
echo "Welcome! ";
echo "<br/>";
echo "<a href="LogOut.php"> Logout </a>";
}

$show_form = false;
$login_result = $emailErr = $passwordErr = '' ;

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

extract($_POST);

if(empty($email)){
$emailErr = "Please enter an email";
$show_form = true;
} else {
$email = ($email);
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$emailErr = "Invalid email format";
$show_form = true;
}
}

if(empty($password)){
$passwordErr = "Please enter a password";
$show_form = true;
}

if( (!empty($email)) && (!empty($password)) && (!$show_form)){
$password = md5($password);

$search = " SELECT * FROM LoginInfo WHERE email = '$email' AND password = '$password' ";
$result = $db ->query($search);


if($result->num_rows == 1){

$row = $result->fetch_assoc();

echo "Welcome to our site";
echo "<br/>";
echo "<a href="LogOut.php"> Logout </a>";

if(isset($remember_me))
{
$cookie_name = "user";
$cookie_value = $row['email'];
setcookie($cookie_name, $cookie_value, time() + (86400 * 7), "/"); // 86400 = 1 day
}

$db->close();
} else { echo "Invalid credentials"; $show_form = true; }

} else{
$login_result = "Invalid credentials" ;
$show_form = true;
}

}

}

else {
$show_form = true;
}

if($show_form){
?>

<div id="content-wrapper">

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td> <label for="email"> Email: </label> </td>
<td>
<input type="email" name="email" id="email" required="required" />
</td>
</tr>
<tr>
<td> <label for="password"> Password: </label> </td>
<td>
<input type="password" name="password" required="required" />
</td>
</tr>

<tr>
<td> <input type="checkbox" name="remember_me"> Remember me </td>
</tr>

<div class="error">
<?php echo $login_result; ?>
</div>

<tr>
<td> <input type="submit" id="login_btn" name="submit" value="Log In"/> </td>
</tr>
</table>
</form>
</fieldset>

<?php
}

?>

Warning: mysqli::_constructO: (HY000/1044): Access denied for user"@'localhost' to database 'icoolsho_sminutti' in C:xampp htdocs Project LogIn.php on line 6 Email Password Remember me Log In

Explanation / Answer

please check once with following credentials

<?php
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'icoolsho_sminutti';

please let me know if you have any clarifications. Thank you...