For this assignment, create an html page that has a login form. The form should have 3 input elements --
1. This should have a type text for the user to enter UserName
2. This should have a type password (like text except cannot see the text that is typed in), for the user to enter password.
3. Submit button (type submit, as we did in class on 2/6).
The form method should be set to POST and the action should be a php script (saved in a .php file).
The php script checks the userName and Password. If it is one of the following, then the page shows "You have successfully logged in!"
User Name Password
elliez tr789ial
greatGuy abc123
blogger 23seventeen23
If the userName and Password do not match the above, the the page shows "Sorry, wrong information has been entered"!
PART TWO
In your php script declares two arrays (or a two dimensional array!) that holds 10 user names and 10 passwords. Using a loop, check to see if the user input matches one of the ten pairs. Print the same messages as in PART ONE above. (We will cover this on Wednesday 2/8 or Wed 2/15)
PART THREE
Read: http://security.stackexchange.com/questions/17816/username-and-or-password-invalid-why-do-websites-show-this-kind-of-message-i
In your php code above, place a comment that (in under four sentences) explains what type of error message a website gives when logon credentials are incorrect, and why this is the message.
PART ONE
HTML PAGE
<html>
<body>
<form id='login' action='login.php' method='post'
accept-charset='UTF-8'>
<fieldset >
<legend>Login</legend>
<input type='hidden' name='submitted' id='submitted'
value='1'/>
<label for='username' >UserName*:</label>
<input type='text' name='username' id='username' maxlength="50"
/>
<label for='password' >Password*:</label>
<input type='password' name='password' id='password'
maxlength="50" />
<input type='submit' name='Submit' value='Submit' />
</fieldset>
</form>
</body>
</html>
login.php FILE
<?php
function Login()
{
if(empty($_POST['username']))
{
$this->HandleError("UserName is empty!");
return false;
}
if(empty($_POST['password']))
{
$this->HandleError("Password is empty!");
return false;
}
$username = trim($_POST['username']);
$password = trim($_POST['password']);
if( ($username == 'elliez' && $password == 'tr789ial')
||
($username == 'greatGuy' && $password ==
'abc123') ||
($username == 'blogger' && $password ==
'23seventeen23'))
{
echo "You have successfully logged in!";
return true;
}
echo "Sorry, wrong information has been entered!";
return false;
}
?>
PART TWO
Change only your login.phph file to use associative array instead of hard-coding the username and password combination in your code.
<?php
function Login()
{
$logins = array(
'username1' => 'password1',
'username2' => 'password2',
'username3' => 'password3',
);
if(empty($_POST['username']))
{
$this->HandleError("UserName is empty!");
return false;
}
if(empty($_POST['password']))
{
$this->HandleError("Password is empty!");
return false;
}
$username = trim($_POST['username']);
$password = trim($_POST['password']);
if( ! isset($logins[$username]) or $logins[$username] !=
$password)
{
echo "Sorry, wrong information has been entered!";
return false;
}
echo "You have successfully logged in!";
return true;
}
?>
Get Answers For Free
Most questions answered within 1 hours.