Projects
Password checker code
Here is an example of what I can do with PHP! I created a password checker that makes sure a password is a strong password!
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Password Tester</title>
<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″ />
</head>
<body>
<p>
<script language=”php”>
//load selected passwords for checking
$passwords=array(
“NoDigitsOrOthers”,
“NoDigits…”,
“NoOthers999″,
“2 Spaces !”,
“0LOWERCASE?”,
“0uppercase+”,
“Sh0r+”,
“This1IsMuchTooLongForAPassword!”,
“1GoodPassword.”,
“GoodPassword2!”
);
// create a function to act as the password checker
Function password_checker($passwords)
{
// create a password strength meter
$isstrong=7;
//1the string should have atleast 8 char
if(preg_match(“/.{8}/”,$passwords)==0)
{
echo “<p>$passwords is not a strong password:It does not contain the minimum amount of charactors”;
// password is getting “weaker”
$isstrong= –$isstrong;
}
//2the string must contain fewer than 16 chars
if(preg_match(“/.{17}/”,$passwords)==1)
{
echo “<p>$passwords is not a strong password:It contains too many charactors</p>”;
// password is getting “weaker”
$isstrong= –$isstrong;
}
//3string must have atleast 1 number
if(preg_match(“/[0-9]{1,}/”,$passwords)==0)
{
echo “<p>$passwords is not a strong password:It does not contain enough numbers</p>”;
// password is getting “weaker”
$isstrong= –$isstrong;
}
//4string must have atleast one uppercase letter
if(preg_match(“/[A-Z]{1,}/”,$passwords)==0)
{
echo “<p>$passwords is not a strong password:It does not contain enough upper case letters</p>”;
// password is getting “weaker”
$isstrong= –$isstrong;
}
//5string must contain atleast one loweracase letter
if(preg_match(“/[a-z]{1,}/”,$passwords)==0)
{
echo “<p>$passwords is not a strong password:It does not contain enough lower case letters</p>”;
// password is getting “weaker”
$isstrong= –$isstrong;
}
//6string must have atleast one non letter or non number char
if(preg_match(“/[^0-9A-Za-z]{1,}/”,$passwords)==0)
{
echo “<p>$passwords is not a strong password:It does not contain enough non numeric or letter chars</p>”;
// password is getting “weaker”
$isstrong= –$isstrong;
}
//7string cant have spaces
if(preg_match(“/\s/”,$passwords)==1)
{
echo “<p>$passwords is not a strong password: It cannot contain spaces</p>”;
// password is getting “weaker”
$isstrong= –$isstrong;
}
if($isstrong==7)
{
echo “<p>$passwords is a strong password</p>”;
}
}
// check all passwords in list
// set array bound for iterating through an array of any length
$arraybound=count($passwords);
for ($passtrial = 0; $passtrial < $arraybound; $passtrial++)
{
password_checker($passwords[$passtrial]);
}
</script>
</p>
</body>
</html>
Paycheck calculator
Here is the form handler of a paycheck calculator I created as part a project on my PHP course. I found it useful calculating how much I would be making simply from my phone.
<h2 style=”text-align: center “> Process Paycheck Data</h2>
<?php
$totalcheck=0;
$overtimepay=0;
$overtimehr=0;
$totalhours=0;
$finalcheck=0;
// calculate paycheck
$HoursWorked= $_POST[‘hours’];
$HourlyWage= $_POST[‘wage’];
//cover overtime
if($HoursWorked>40)
{
$overtimehr=($HoursWorked-40);
$overtimewage=($HourlyWage*1.5);
$totalcheck= 40*$HourlyWage;
$overtimepay= $overtimehr*$overtimewage;
$totalhours=$overtimehr+40;
$finalcheck=$overtimepay+$totalcheck;
echo “<p>40 hours @ $HourlyWage /hr = \$$totalcheck</p>”;
echo “<p>$overtimehr hours @ $overtimewage /hr = \$$overtimepay</p>”;
echo “<p> Total for $totalhours hours is \$$finalcheck </p> “;
}
else
{
if($error==0)
{
$totalcheck=$HoursWorked*$HourlyWage;
echo “<p> $HoursWorked @ $HourlyWage /hr = \$ $totalcheck</p>”;
}
}
print( ‘<a href=”http://127.0.0.1/paycheck.html”>Caluclate Another Paycheck</a>’);
?>