So, I’ve got a small registration script (create a username, password, and reCaptcha). I have another registration script that I created at http://www.php-login-script.com. It contains things like Name, Phone#, Gender, Email, etc, etc… I’m trying to combine them.
I like the extensive features of the one I created at php-login-script.com, but I need the security created in the small registration script. I’ve posted them both here, and I’ve tried combining them, but I keep FAILING. Please help, if you can…
Small Registration Script…
[php]<?php
//require user configuration and database connection parameters
require(‘config.php’);
//pre-define validation parameters
$usernamenotempty=TRUE;
$usernamevalidate=TRUE;
$usernamenotduplicate=TRUE;
$passwordnotempty=TRUE;
$passwordmatch=TRUE;
$passwordvalidate=TRUE;
$captchavalidation= TRUE;
//Check if user submitted the desired password and username
if ((isset($_POST[“desired_password”])) && (isset($_POST[“desired_username”])) && (isset($_POST[“desired_password1”]))) {
//Username and Password has been submitted by the user
//Receive and validate the submitted information
//sanitize user inputs
function sanitize($data){
$data=trim($data);
$data=htmlspecialchars($data);
$data=mysql_real_escape_string($data);
return $data;
}
$desired_username=sanitize($_POST[“desired_username”]);
$desired_password=sanitize($_POST[“desired_password”]);
$desired_password1=sanitize($_POST[“desired_password1”]);
//validate username
if (empty($desired_username)) {
$usernamenotempty=FALSE;
} else {
$usernamenotempty=TRUE;
}
if ((!(ctype_alnum($desired_username))) || ((strlen($desired_username)) >11)) {
$usernamevalidate=FALSE;
} else {
$usernamevalidate=TRUE;
}
if (!($fetch = mysql_fetch_array( mysql_query(“SELECT username
FROM authentication
WHERE username
=’$desired_username’”)))) {
//no records for this user in the MySQL database
$usernamenotduplicate=TRUE;
}
else {
$usernamenotduplicate=FALSE;
}
//validate password
if (empty($desired_password)) {
$passwordnotempty=FALSE;
} else {
$passwordnotempty=TRUE;
}
if ((!(ctype_alnum($desired_password))) || ((strlen($desired_password)) < 8)) {
$passwordvalidate=FALSE;
} else {
$passwordvalidate=TRUE;
}
if ($desired_password==$desired_password1) {
$passwordmatch=TRUE;
} else {
$passwordmatch=FALSE;
}
//Validate recaptcha
require_once(‘recaptchalib.php’);
$resp = recaptcha_check_answer ($privatekey,
$_SERVER[“REMOTE_ADDR”],
$_POST[“recaptcha_challenge_field”],
$_POST[“recaptcha_response_field”]);
if (!$resp->is_valid) {
//captcha validation fails
$captchavalidation=FALSE;
} else {
$captchavalidation=TRUE;
}
if (($usernamenotempty==TRUE)
&& ($usernamevalidate==TRUE)
&& ($usernamenotduplicate==TRUE)
&& ($passwordnotempty==TRUE)
&& ($passwordmatch==TRUE)
&& ($passwordvalidate==TRUE)
&& ($captchavalidation==TRUE)) {
//The username, password and recaptcha validation succeeds.
//Hash the password
//This is very important for security reasons because once the password has been compromised,
//The attacker cannot still get the plain text password equivalent without brute force.
function HashPassword($input)
{
//Credits: http://crackstation.net/hashing-security.html
//This is secure hashing the consist of strong hash algorithm sha 256 and using highly random salt
$salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
$hash = hash(“sha256”, $salt . $input);
$final = $salt . $hash;
return $final;
}
$hashedpassword= HashPassword($desired_password);
//Insert username and the hashed password to MySQL database
mysql_query(“INSERT INTO authentication
(username
, password
) VALUES (’$desired_username’, ‘$hashedpassword’)”) or die(mysql_error());
//Send notification to webmaster
$message = “Someone has just registered at JPC Solutions Sports Page: $desired_username”;
mail($email, $subject, $message, $from);
//redirect to login page
header(sprintf(“Location: %s”, $loginpage_url));
exit;
}
}
?>
Register as a Valid User
.invalid {
border: 1px solid #000000;
background: #FF00FF;
}
User registration Form
Hi! Welcome to my page. We're gladd you're here. We invite you to register your information below. Thanks!
Username: (
alphanumeric less than 12 characters) " id="desired_username" name="desired_username">
Password: (
alphanumeric greater than 8 characters) " id="desired_password" >
Type the password again: " id="desired_password1" >
Type the captcha below:
<?php
require_once('recaptchalib.php');
echo recaptcha_get_html($publickey);
?>
Back to Homepage
<?php if ($captchavalidation==FALSE) echo 'Please enter correct captcha'; ?>
<?php if ($usernamenotempty==FALSE) echo 'You have entered an empty username.'; ?>
<?php if ($usernamevalidate==FALSE) echo 'Your username should be alphanumeric and less than 12 characters.'; ?>
<?php if ($usernamenotduplicate==FALSE) echo 'Please choose another username, your username is already used.'; ?>
<?php if ($passwordnotempty==FALSE) echo 'Your password is empty.'; ?>
<?php if ($passwordmatch==FALSE) echo 'Your password does not match.'; ?>
<?php if ($passwordvalidate==FALSE) echo 'Your password should be alphanumeric and greater 8 characters.'; ?>
<?php if ($captchavalidation==FALSE) echo 'Your captcha is invalid.'; ?>
[/php]
Here is the form script created at php-login-script.com
[php]<?php
This block must be placed at the very top of page.
--------------------------------------------------
require_once( dirname(FILE).’/form.lib.php’ );
phpfmg_display_form();
--------------------------------------------------
function phpfmg_form( $sErr = false ){
$style=" class=‘form_text’ ";
?>
Please check the required fields
-
Basic Information
-
First Name *
-
Last Name *
-
Phone Number
-
Create a Password *
-
Gender *
<?php phpfmg_dropdown( 'field_5', "Male|Female|Prefer Not to Answer" );?>
-
Email Address
-
Additional Information
-
Street Address *
-
City *
-
State *
<?php phpfmg_dropdown( 'field_10', "Arizona|Alabama|Alaska||Arkansas|California|Colorado|Connecticut|Delaware|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming" );?>
-
Zip Code *
-
Date of Birth *
<?php
$field_12 = array(
'month' => "-MM- =,|01|02|03|04|05|06|07|08|09|10|11|12",
'day' => "-DD- =,|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31",
'startYear' => date("Y")+0,
'endYear' => date("Y")-62,
'yearPrompt' => '-YYYY-',
'format' => "mm/dd/yyyy",
'separator' => "/",
'field_name' => "field_12",
);
phpfmg_date_dropdown( $field_12 );
?>
<div id='field_12_tip' class='instruction'></div>
</div>
-
Free Agents - Select Which Leagues you are Interested in Playing for...
-
Please select a league *
<?php phpfmg_checkboxes( 'field_14', "Tuesday Co-Ed|Friday Co-Ed|Saturday Soccer League|Sunday Soccer League|Flag Football|Kickball|Women's Soccer" );?>
-
-
Please send us your comments!
<?php phpfmg_hsc("field_16"); ?>
<div id='field_16_tip' class='instruction'></div>
</div>
-
Security Code: *
<?php phpfmg_show_captcha(); ?>
<li>
<div class='col_label'> </div>
<div class='form_submit_block col_field'>
<input type='submit' value='Submit' class='form_button'>
<span id='phpfmg_processing' style='display:none;'>
<img id='phpfmg_processing_gif' src='<?php echo PHPFMG_ADMIN_URL . '?mod=image&func=processing' ;?>' border=0 alt='Processing...'> <label id='phpfmg_processing_dots'></label>
</span>
</div>
</li>
<?php
phpfmg_javascript($sErr);
}
# end of form
function phpfmg_form_css(){
?>
body{
margin-left: 18px;
margin-top: 18px;
}
body{
font-family : Verdana, Arial, Helvetica, sans-serif;
font-size : 13px;
color : #474747;
background-color: transparent;
}
select, option{
font-size:13px;
}
ol.phpfmg_form{
list-style-type:none;
padding:0px;
margin:0px;
}
ol.phpfmg_form li{
margin-bottom:5px;
clear:both;
display:block;
overflow:hidden;
width: 100%
}
.form_field, .form_required{
font-weight : bold;
}
.form_required{
color:red;
margin-right:8px;
}
.field_block_over{
}
.form_submit_block{
padding-top: 3px;
}
.text_box, .text_area, .text_select {
width:300px;
}
.text_area{
height:80px;
}
.form_error_title{
font-weight: bold;
color: red;
}
.form_error{
background-color: #F4F6E5;
border: 1px dashed #ff0000;
padding: 10px;
margin-bottom: 10px;
}
.form_error_highlight{
background-color: #F4F6E5;
border-bottom: 1px dashed #ff0000;
}
div.instruction_error{
color: red;
font-weight:bold;
}
hr.sectionbreak{
height:1px;
color: #ccc;
}
#one_entry_msg{
background-color: #F4F6E5;
border: 1px dashed #ff0000;
padding: 10px;
margin-bottom: 10px;
}
<?php phpfmg_text_align();?>
<?php
}
# end of css
?>[/php]