Username (6-12 chars, alphanumeric only. Cannot start with a number)
Password (6-12 chars, alphanumeric requiring 1 letter (any case) and 1 number)
Password Confirmation
Email (I used the built in PHP function to check this. Is it bad?)
Email Confirmation
Here is the only function that is called from outside the file. I copied it from a book. I am aware that there will be a different function for when I start in with the MySQL inserts, but I'm not ready for that yet.
function sanstring($input) {
$input = stripslashes($input);
$input = htmlentities($input);
$input = strip_tags($input);
return $input;
}
And here's the page content.
<?php
require_once 'header.php';
require_once 'config.php'; #for salts.
require_once 'code.php'; #for sanstring()
if (isset($_POST['submit'])) {
/*
* ----------ERROR CHECKING HERE
*/
$error = $username = $password = $confpassword = $email = $confemail = "";
if ($_POST['username']) {
$username = sanstring($_POST['username']);
if (strlen($username) > 12)
$error .= '<div>The username you entered is too long. Username must be 6 to 12 characters.</div>';
if (strlen($username) < 6)
$error .= '<div>The username you entered is too short. Username must be 6 to 12 characters.</div>';
if (preg_match('/[^a-z0-9_]/', $username))
$error .= '<div>The username you entered contains invalid characters. Username may contain A-Z, a-z, 0-9, and _.</div>';
} else {
$error .= '<div>You did not enter a username. Please try again.</div>';
}if ($_POST['password']) {
$password = sanstring($_POST['password']);
if (strlen($password) > 12)
$error .= '<div>The password you entered is too long. Password must be 6 to 12 characters.</div>';
if (strlen($password) < 6)
$error .= '<div>The password you entered is too short. Password must be 6 to 12 characters.</div>';
if (preg_match('/[^a-z0-9]i/', $password))
$error .= '<div>The password you entered contains invalid characters. Password may contain A-Z, a-z, 0-9, and !@#$%^&*()</div>';
} else {
$error .= '<div>You did not enter a password. Please try again.</div>';
}if ($_POST['confpassword']) {
$confpassword = sanstring($_POST['confpassword']);
if (strcmp($password, $confpassword))
$error .= '<div>The password confirmation does not match your password. Please try again.</div>';
} else {
$error .= '<div>You did not enter your password confirmation. Please try again.</div>';
}
if ($_POST['email']) {
$email = sanstring($_POST['email']);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $error .= '<div>The email you entered is not valid.</div>';
} else {
$error .= '<div>You did not enter your email address. Please try again.</div>';
}if ($_POST['confemail']) {
$confemail = sanstring($_POST['confemail']);
if (strcasecmp($email, $confemail))
$error .= '<div>The email confirmation does not match your email. Please try again.</div>';
} else {
$error .= '<div>You did not enter your email confirmation. Please try again.</div>';
}
if ($error) {
echo $error;
} else {
/*
* ---------CODE IF NO ERRORS EXIST
*/
$password = md5($salt1 . $password . $salt2); #salts are in config.php
}
} else {
echo <<< _END
<div>
<form action="register.php" method="post">
Desired Username: <input type="text" maxlength="16" name="username" /><br />
Desired Password: <input type="password" maxlength="16" name="password" /><br />
Confirm Password: <input type="password" maxlength="16" name="confpassword" /><br />
Email Address: <input type="text" name="email" /><br />
Confirm Email: <input type="text" name="confemail" /><br />
<input name="submit" type="submit" value="Submit" />
</form>
</div>
_END;
}
/*
* TODO:
* Function to ensure username starts with a letter.
* Function to ensure password contains one letter and one number.
*
*/
?>
Thank you for your input!

New Topic/Question
Reply



MultiQuote






|