Hi there, wonder if anyone can look over the below and check for any potential errors, vulnerabilities or just a better, neater way of doing it. I am getting to grips with PHP so appreciate any comments on how I can improve what I've done thus far.
The script takes the inputted username and password, checks that they do not match, or that either is less than 3 characters or more than 10. Also strips any html from the username field to prevent XSS (though max char is 10!)
So, simple HTML form:
And the submit.php file which the form will use to process the input:Code:<form action="submit.php" method="post" > Username (min 3 char, max 10 char):<br> <input name="username" type="text"><br> Password (min 3 char, max 10 char)<br> <input name="password" type="password"><br> <input name="submit" type="submit" value="submit"> </form>
I think die() perhaps isn't what I shouldn't be using the stop the script after a condition?Code:<?php $username = $_POST['username']; //get submitted username from form $password = $_POST['password']; //get submitted password from form if (($password == NULL) || ($username == NULL)) { echo "Missing username or password."; //stop here if a u/pw was not entered die(); } if ($username == $password) { echo "Username and password must not match!"; die(); } if (strlen($username) < 3 || strlen($username) > 10) { // if USERNAME is less than 3 or more than 10... echo "Your username is less than 3 or more than 10!"; die(); //stop here if username is less than 3 or more than 10 } elseif (strlen($password) < 3 || strlen($password) > 10) { // if PASSWORD is less than 3 or more than 10... echo "Your password is less than 3 or more than 10!"; } else { echo "Thank you for signing up. Your username is <b>" . strip_tags($username) . " </b>and your password is <b>$password</b>"; } echo "<br /> <br />"; $password = md5($password); //encrypt the password using md5 echo "Using md5 encryption, your password would be entered into the database as the following $password"; //do something, like put info into db ?>


LinkBack URL
About LinkBacks






Reply With Quote




