Page 1 of 1

register form

Posted: Sat Feb 04, 2012 8:44 am
by digrev01
hi everybody could you plase check my code whenever enter password i get the error message "password must be password must be betwwen 6/25"; anything wrong whit this code ?


<?php

$name=strip_tags( $_POST['fullname']);
$username=strip_tags( $_POST['username']);
$pass=$_POST['pass'];
$repass=$_POST['repass'];
$submit=$_POST['submit'];
$date=date("Y-m-d");
if(isset($submit))
{

if($name && $username && $pass && $repass)

{

$pass=md5($pass);
$repass=md5($repass);
if($pass=$repass)
{
if(strlen($name)>25 || strlen($repass)<6 )
{
echo "username or fullname are too long";

}
else
{


if(strlen($pass)>25 || strlen($pass)<6)
{
echo "password must be betwwen 6/25";

}
else
{
echo "ok";
//register

}

}
}
else
{
echo "passwords dont match";
}

}

echo "fill all the fields";
}






?>

<html>
<form action="register.php" method="post">

<table width="200" border="1">
<tr>
<td height="41">Full Name </td>
<td><label>
<input type="text" name="fullname" />
</label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><p>Choose</p>
<p> Nickname </p></td>
<td><label>
<input type="text" name="username" />
</label></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>RePassword</td>
<td><label>
<input type="password" name="repass" />
</label></td>
<td>&nbsp;</td>
</tr>
</table>

<br />
<input name="submit" type="submit" value="register" />


</form>
</html>

Re: register form

Posted: Sat Feb 04, 2012 10:25 am
by Celauran
There's plenty wrong with that code. First, it's not between [ syntax=php] tags.

Code: Select all

$date = date("Y-m-d");
You never use the variable, so why are you initializing it?

Code: Select all

if ($pass = $repass)
You're using the assignment operator (=) when you want to be using a comparison operator (==).

Code: Select all

if (strlen($name) > 25 || strlen($repass) < 6)
{
    echo "username or fullname are too long";
}
This can't possibly be right. strlen($repass) will always be 32 because it has been md5 hashed. You probably meant strlen($username) > something.

Code: Select all

if (strlen($pass) > 25 || strlen($pass) < 6)
{
    echo "password must be betwwen 6/25";
}
You've already hashed the passwords, so the length will always be 32. Check the plain text passwords, then hash them. Also, don't use md5.

Code: Select all

<table width="200" border="1">
You shouldn't be using tables for layout, nor should you use deprecated, inline styling.

Re: register form

Posted: Sat Feb 04, 2012 11:10 am
by digrev01
thank you celauren it works now