Username Limit!

z00h94

New Member
Messages
3
Reaction score
0
Points
0
Hello, can somebody tell me how to add a username limit to registering system!

Here's the code:
Code:
[SIZE=2]<html>[/SIZE]
[SIZE=2]<link rel="stylesheet" href="style.css" type="text/css">[/SIZE]
[SIZE=2]<center>[/SIZE]
[SIZE=2]<table class='maintable'>[/SIZE]
[SIZE=2]<tr class='headline'><td><center>Register</center></td></tr>[/SIZE]
[SIZE=2]<tr class='mainrow'><td><center>[/SIZE]
[SIZE=2]<table border='0'><tr class='mainrow'><td>[/SIZE]
[SIZE=2]<form method="post" action="reguser.php">[/SIZE]
[SIZE=2]Type Username Here*:</td><td><input type="text" name="username" size="15"></td></tr>[/SIZE]
[SIZE=2]<tr class='mainrow'><td>Type Password Here*:</td><td><input type="password" name="password" size="15"></td></tr>[/SIZE]
[SIZE=2]<tr class='mainrow'><td>Type Email Here*:</td><td><input type='email' name='email' size='15'></td></tr>[/SIZE]
[SIZE=2]<tr class='mainrow'><td></td><td><input type="submit" value="submit">[/SIZE]
[SIZE=2]</center>[/SIZE]
[SIZE=2]</form>[/SIZE]
[SIZE=2]</td></tr></table>[/SIZE]
[SIZE=2]</html>[/SIZE]
 

LHVWB

New Member
Messages
1,308
Reaction score
0
Points
0
See the 'Size="15"', that should be limiting the number of characters for that field, however its not very secure. I would recomment that you put an 'if' statement in your reguser.php file which also checks the username length.

You should use the strlen() function like the example below.

PHP:
<?php
    //  Check for valid username length
    if(strlen($_POST['username']) <= 15)
    {
         // Register the user
    }
    else
    {
        // Redirect user back to form with error message.
    }
?>
 

TechAsh

Retired
Messages
5,853
Reaction score
7
Points
38
The size= tag limits the size of the visble area of the field, it doesn't limit how many characters may be entered.

Use the maxlength= tag.

You code may look like:
Code:
<html>
<link rel="stylesheet" href="style.css" type="text/css">
<center>
<table class='maintable'>
<tr class='headline'><td><center>Register</center></td></tr>
<tr class='mainrow'><td><center>
<table border='0'><tr class='mainrow'><td>
<form method="post" action="reguser.php">
Type Username Here*:</td><td><input type="text" name="username" size="15" maxlength="15"></td></tr>
<tr class='mainrow'><td>Type Password Here*:</td><td><input type="password" name="password" size="15"></td></tr>
<tr class='mainrow'><td>Type Email Here*:</td><td><input type='email' name='email' size='15'></td></tr>
<tr class='mainrow'><td></td><td><input type="submit" value="submit">
</center>
</form>
</td></tr></table>
</html>

However as LHVWB said that isn't very secure and you should also do what he said. So use both solutions for the best result.
 
Last edited:

z00h94

New Member
Messages
3
Reaction score
0
Points
0
thx but i know nothing about php

Here's the reguser file:
Code:
[SIZE=2]
<?php
include "connect.php";
?>
<link rel="stylesheet" href="style.css" type="text/css">
<?php
print "<center>";
print "<table class='maintable'>";
print "<tr class='headline'><td><font color='white'><center>Register</center></td></tr>";
print "<tr class='mainrow'><td><center>";
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];
$password=md5($password);
$randsseed=date("U")%10000000;
srand($randsseed);
$validationkey=rand(1000,100000000);
$validationkey=md5($validationkey);
$checkemail="SELECT eatid from eatyou_login where eatemail='$email' or eatname='$username'";
$checkmail2=mysql_query($checkemail) or die("Could not check emails");
$checkmail3=mysql_num_rows($checkmail2);
if(strlen($username)<3)
{
print "Username have to be at least 4 characters long.";
print "Username too long Max 10.";
}
else if($checkmail3>0)
{
print "There is already another player with that email address or that name.";
}
else
{
$insertadmin="INSERT into eatyou_login (eatname,eatpass,eatvalidated,validkey,eatemail) values('$username','$password','0','$validationkey','$email')";
mysql_query($insertadmin) or die(mysql_error());
mail($email,"Pwn you game registration","Thank you for registering, please validate your account by clicking this link $path/validated.php?user=$username&validatekey=$validationkey",$yourmail);
print "Player Registered, you will need to validate your account with the validation code sent to your email.";
print "</td></tr></table>";
}
?>
[/SIZE]

can u guys plz ready the whole thing so i can use it
 

TechAsh

Retired
Messages
5,853
Reaction score
7
Points
38
I would do:
PHP:
<?php
include "connect.php";
?>
<link rel="stylesheet" href="style.css" type="text/css">
<?php
print "<center>";
print "<table class='maintable'>";
print "<tr class='headline'><td><font color='white'><center>Register</center></td></tr>";
print "<tr class='mainrow'><td><center>";
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];
$password=md5($password);
$randsseed=date("U")%10000000;
srand($randsseed);
$validationkey=rand(1000,100000000);
$validationkey=md5($validationkey);
$checkemail="SELECT eatid from eatyou_login where eatemail='$email' or eatname='$username'";
$checkmail2=mysql_query($checkemail) or die("Could not check emails");
$checkmail3=mysql_num_rows($checkmail2);
if(strlen($username)<=3)
{
print "Username have to be at least 4 characters long.";
print "Username too short Min 3.";
}
elseif(strlen($username) >= 15) {
print "Username too long. Max: 15";
}
else if($checkmail3>0)
{
print "There is already another player with that email address or that name.";
}
else
{
$insertadmin="INSERT into eatyou_login (eatname,eatpass,eatvalidated,validkey,eatemail) values('$username','$password','0','$validationkey','$email')";
mysql_query($insertadmin) or die(mysql_error());
mail($email,"Pwn you game registration","Thank you for registering, please validate your account by clicking this link $path/validated.php?user=$username&validatekey=$validationkey",$yourmail);
print "Player Registered, you will need to validate your account with the validation code sent to your email.";
print "</td></tr></table>";
}
?>

So if you use both that code and the code I posted in my previous post, everything should work. Post back if it doesn't.

EDIT: I've just fixed an error.
 
Last edited:

marshian

New Member
Messages
526
Reaction score
9
Points
0
This is not the right forum to post this, it should be in programming help...
 

TechAsh

Retired
Messages
5,853
Reaction score
7
Points
38
This is not the right forum to post this, it should be in programming help...

Either sunils or a Senior Mod will move it when they find it. Don't worry.
This isn't my Forum so I won't move it.

EDIT: I've just noticed that sunils is on hoilday, so it'll be a senior mod who'll move it.
 
Last edited:

VPmase

New Member
Messages
914
Reaction score
1
Points
0
Either sunils or a Senior Mod will move it when they find it. Don't worry.
This isn't my Forum so I won't move it.

EDIT: I've just noticed that sunils is on hoilday, so it'll be a senior mod who'll move it.
Why's that? It shouldn't matter who moves it just as long as its moved ><... Plus, the uppers are free all the time and its not like they always check every forum.

*moved*
 
Last edited:

phpasks

New Member
Messages
145
Reaction score
0
Points
0
PHP:
<?php

    function check_Blank($myfld,$field_name)
    {
        if(strlen(trim($myfld))==0)
            return "Enter " . $field_name . "<br />" ;  
        return;
    }
    
   function check_Length($myfld, $minValue, $maxValue, $field_name="")
   {    
          if ( strlen($myfld) >= $minValue && strlen($myfld)<=$maxValue )
             return "";
          else 
             return $field_name . " must be minimum of " . $minValue ." and maximum of " . $maxValue ." characters<br>";
    }
    function check_Email($sEmailAddress,$field_name)
    {
        if (ord(check_Length($sEmailAddress,"7","75"))==0)
        {    
             if (!eregi("^[-_a-z0-9]+(\.[-_a-z0-9-]+)*@[a-z0-9]+(\.[a-z0-9]+)*(\.[a-z]{2,3})$",$sEmailAddress))
            {
                return "Enter Valid " .$field_name."<br>";
            }        
            return "";
        } else {
            return "Enter Valid " .$field_name."<br>";         
        }
    }
        $err["username"]    =    check_Blank($str_username,"Email");

        if (strlen($err["username"])==0) {
            $err["username"]    =    check_length($str_username,7,75,"Email");
        }

        if (strlen($err["username"])==0) {
            $err["username"]    =    check_Email($str_username,"Email");
        }

?>

using this for username checking not blank, username min & max size, Email checking
 
Top