Revision: 44462
Updated Code
at April 12, 2011 06:32 by Haddman
Updated Code
function register( $user, $pass, $pass2 )
{
if ( isset( $_POST['register'] ) )
{
//Escape is a function with mysql_real_escape_string() and more
$user = escape( $user );
$pass = escape( $pass );
$pass2 = escape( $pass2 );
if ( empty( $user ) )
{
$error = "Username missing!";
}
else if ( empty( $pass ) )
{
$error = "Password missing!";
}
else if ( empty( $pass2 ) )
{
$error = "Please repeat your password!";
}
else if ( $pass != $pass2 )
{
$error = "Your passwords do not match!";
}
else if ( strlen( $user ) > 25 )
{
$error = "Username is to long, 25 characters max!";
}
else if ( strlen( $pass ) > 25 )
{
$error = "Password is to long, 25 characters max!";
}
else if ( strlen( $pass ) < 5 )
{
$error = "Password is to short, 5 characters min!";
}
//I use trim to check if a user has a username with only whitespace, not using regex since having a whitespace in the username should be ok
else if ( trim( $user ) == "" )
{
$error = "Usernames only containing white-spaces is not allowed!";
}
else
{
$fetch = mysql_query( "SELECT `user` FROM `user` WHERE `user` = '".$user."'" ) or die ( mysql_error() );
if ( mysql_num_rows( $fetch ) != 0 )
{
$error = "That username is already taken!";
}
else
{
$pass = md5( $pass );
mysql_query( "INSERT INTO `user` ( `user`, `pass` ) VALUES ( '".$user."', '".$pass."' )" ) or die ( mysql_error() );
}
}
}
}
Revision: 44461
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at April 12, 2011 06:28 by Haddman
Initial Code
function register( $user, $pass, $pass2 )
{
if ( isset( $_POST['register'] ) )
{
$user = escape( $user );
$pass = escape( $pass );
$pass2 = escape( $pass2 );
if ( empty( $user ) )
{
$error = "Username missing!";
}
else if ( empty( $pass ) )
{
$error = "Password missing!";
}
else if ( empty( $pass2 ) )
{
$error = "Please repeat your password!";
}
else if ( $pass != $pass2 )
{
$error = "Your passwords do not match!";
}
else if ( strlen( $user ) > 25 )
{
$error = "Username is to long, 25 characters max!";
}
else if ( strlen( $pass ) > 25 )
{
$error = "Password is to long, 25 characters max!";
}
else if ( strlen( $pass ) < 5 )
{
$error = "Password is to short, 5 characters min!";
}
else if ( trim( $user ) == "" )
{
$error = "Usernames only containing white-spaces is not allowed!";
}
else
{
$fetch = mysql_query( "SELECT `user` FROM `user` WHERE `user` = '".$user."'" ) or die ( mysql_error() );
if ( mysql_num_rows( $fetch ) != 0 )
{
$error = "That username is already taken!";
}
else
{
$pass = md5( $pass );
mysql_query( "INSERT INTO `user` ( `user`, `pass` ) VALUES ( '".$user."', '".$pass."' )" ) or die ( mysql_error() );
$error = "Registration complete, continue to login via the \"Back\" link below.";
}
}
}
}
Initial URL
Initial Description
Initial Title
Simple Register Function
Initial Tags
Initial Language
PHP