Question

In: Computer Science

//instructions Form: There should be at least 2 input fields for username and password. Use an...

  • //instructions
  • Form:
    • There should be at least 2 input fields for username and password.
  • Use an array as a database in which there are several usernames and passwords:
    • Usernames can be either emails or nick names (WITHOUT WHITE SPACE)
  • After the user submitted the form, students must:
    • sanitize the inputs
    • check if there is a match with one username and one password in the array.
    • If there is no match, print out an error message to user on the form.
    • If it is a match, redirect the user to a welcome page.

//code

   if(isset($_GET['submit'])){

//sanitize the input
      
/* Check the error from the input:
if input from user is empty
-> get an error string variable
if input is not empty
-> use preg_match() to match the pattern
$pattern = "/^[1-9][0-9]{2}(\.|\-)[0-9]{3}(\.|\-)[0-9]{4}$/";
-> if it's a matched, get a success string variable
*/
      
   }
?>






Lab 2-Part1

  



Phone Number
>
xxx.xxx.xxx or xxx-xxx-xxxx


     


          Must enter a valid phone number!
         


         


          Phone number is valid!
         



  
Submit






Solutions

Expert Solution

<?php
session_start(); //initiates the sessions

//begin testing
$_POST['user'] = 'username1';
$_POST['submit'] = true;
$_POST['password'] = 'pass3';
//end  testing

if (isset($_POST['submit'])) //checks to make sure the login form has been submitted
    {

    $users = array('username1','username2','username3');
    $passwords = array('pass1','pass2','pass3' );
    if(in_array($_POST['user'], $users))
    {
       $key = array_search($_POST['user'], $users);

       if($passwords[$key]==$_POST['password'])
       {
         $_SESSION['access'] = 1; //if login is successful create a session that can be authenticated 
         //header("Location: " . $_SERVER['PHP_SELF']);
         echo "welcome back ".$_POST['user'];
       } else //if password is incorrect reload the login form
        {
         //header("Location: " . $_SERVER['PHP_SELF']);
          echo "Password incorrect, error, redirecting to login";
        }


    }

    }
else 
{
  echo "Login form";
}
?>

Output:

Password incorrect, error, redirecting to login

But if you change the value of $_POST['password'] to 'pass1', like this:

$_POST['password'] = 'pass1';

You have this output:

welcome back username1

Related Solutions

log in form Requirements: Form: There should be at least 2 input fields for username and...
log in form Requirements: Form: There should be at least 2 input fields for username and password. Use an array as a database in which there are several usernames and passwords: Usernames can be either emails or nick names (WITHOUT WHITE SPACE) After the user submitted the form, students must: sanitize the inputs check if there is a match with one username and one password in the array. If there is no match, print out an error message to user...
Is there a simple way to create a username and password for a registeration form? The...
Is there a simple way to create a username and password for a registeration form? The username should be between 4 and 20 characters. The password should be between 4 and 12 characters, contain at least one digit, and contain at least one uppercase and one lowercase character. Select four special characters and require that the password contain at least one of them.
Create an HTML form with the following: 2 text input fields 1 text area 2 radio...
Create an HTML form with the following: 2 text input fields 1 text area 2 radio buttons or 3 checkboxes 1 button Include labels for fields
VISUAL STUDIO CODE Use a for loop for to create "password". Request the password at least...
VISUAL STUDIO CODE Use a for loop for to create "password". Request the password at least 3 times. If the password is 12345, the procedure ends, if the correct password entered, close excel saving changes. THANKS
Write a JavaScript function to get the values of form containing the following input fields: fname...
Write a JavaScript function to get the values of form containing the following input fields: fname lname address city state
PROGRAM INSTRUCTIONS: 1. Code an application that asks the customer for a log-in and password. 2....
PROGRAM INSTRUCTIONS: 1. Code an application that asks the customer for a log-in and password. 2. The real log-in is "Buffet2011" and the real password is "Rank1Bill2008". 3. Allow the customer two (2) attempts to type either. a. Each time the customer enters an invalid log-in or password issue an error message. b. If the customer fails all two (2) log-in attempts, issue another error message and exit the program. c. If the log-in is successful, the customer can calculate...
Using PHP and MySQL Create a simple web form with at least 5 fields Include validation...
Using PHP and MySQL Create a simple web form with at least 5 fields Include validation and error messages Create a MySQL Database Create a table to store submissions from the form Only insert new data into the database when all validation is passed Use PHP to create an HTML table showing all the content of the database   New submissions should appear in table
PHP The database should have at least two tables with, at minimum, the following fields: Table...
PHP The database should have at least two tables with, at minimum, the following fields: Table customers: Fields: Table billing: Fields: customer_ID customer_ID customer_L_Name customer_L_Name customer_F_Name service customer_Title (Mr, Ms, Dr. etc,) customer_bill street_Address amt_paid city_State_Zip bill_date customer_Phone date_paid customer_Email Create a PHP page that will extract a customer’s bill amount and the amount paid. Then it will calculate the amount due. If the amount due is greater than 0, an email should be generated and sent to the customer...
Instructions JAVA PROGRAMMING 1. Ask the user for a year input (positive integer - should be...
Instructions JAVA PROGRAMMING 1. Ask the user for a year input (positive integer - should be between 1500 and 2019, inclusive). 2. If the year input is not between 1500 and 2019, do not check for leap year, rather print that this year cannot be checked. 3. Take a year input from the user (should be between 1500 and 2019) 4. If the input year is a leap year, print that year is a leap year; otherwise, print that the...
write modules to sort by 2 field then 3 fields then 4 fields Use the data...
write modules to sort by 2 field then 3 fields then 4 fields Use the data Structure to guide you. //HW sort by 5 of these fields and ask the user which field to sort by !!! // Use a custom comparator. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; class Emprec { String name; String address; double hours; double rate; int dependents; char gender; boolean degree; // This is the classes's constructor !!!! Emprec(String name, String address, String hours,String...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT