Newbie Spellweaver
- Joined
- Dec 24, 2013
- Messages
- 85
- Reaction score
- 21
Hey, this is just an add-on to the
Step 1 : Getting Keys
Just go to
Step 2 : Adding in Google's Api.js
Step 3 : Replacing register script
Step 4 : Changing Public/Secret Keys Now that we have replaced the script, we are ready to change the ReCAPTCHA keys (both public and secret) that we created in Step 1.
First navigate to line 30 within the script and place your PUBLIC key where it says "YOUR SITE KEY HERE"
Now go to line 40 and edit where it says "YOUR SECRET SITE KEY" with your SECRET key.
Just save and refresh the register page, and it should work flawlessly!
Credits : greenelfx (for
You must be registered to see links
register script that will allow it to use the Google ReCAPTCHA instead of the old (ugly) one. Step 1 : Getting Keys
Just go to
You must be registered to see links
and fill out the form. Once it's finished you will receive a page that shows you 2 KEYS. You will need both the public and secret key in-order for this to work properly. Just copy both of them on a notepad file for now, until we get to the last step!Step 2 : Adding in Google's Api.js
First find this line of code in "sources/structure/header.php"
Next paste this below.
Code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
Code:
<script src='https://www.google.com/recaptcha/api.js'></script>
Step 3 : Replacing register script
Navigate to /sources/public/register.php and replace the entire file with this code.
Code:
<?php if(basename($_SERVER["PHP_SELF"]) == "register.php"){
die("403 - Access Forbidden");
}
if(isset($_SESSION['id'])){
echo "<meta http-equiv=refresh content="0; url=?base=ucp">";
}
else{
echo "<h2 class="text-left">Registration</h2><hr/>";
if (@$_POST["register"] != "1") {
?>
<form action="?base=main&page=register" method="POST" role="form">
<div class="form-group">
<label for="inputUser">Username</label>
<input type="text" name="musername" maxlength="12" class="form-control" id="inputUser" required autocomplete="off" placeholder="Username">
</div>
<div class="form-group">
<label for="inputPass">Password</label>
<input type="password" name="mpass" maxlength="30" class="form-control" id="inputPass" required autocomplete="off" placeholder="Password">
</div>
<div class="form-group">
<label for="inputConfirm">Confirm Password</label>
<input type="password" name="mpwcheck" maxlength="30" class="form-control" id="inputConfirm" required autocomplete="off" placeholder="Confirm Password">
</div>
<div class="form-group">
<label for="inputEmail">Email</label>
<input type="email" name="memail" maxlength="50" class="form-control" id="inputEmail" required autocomplete="off" placeholder="Email">
</div>
<b>reCaptcha</b>
<div class="g-recaptcha" data-sitekey="YOUR SITE KEY HERE"></div>
<br/>
<input type="submit" class="btn btn-primary" name="submit" alt="Register" value="Register »"/>
<input type="hidden" name="register" value="1" />
</form>
<br/>
<?php
} else {
$getusername = $mysqli->real_escape_string($_POST["musername"]); # Get Username
$username = preg_replace("/[^A-Za-z0-9 ]/", '', $getusername); # Escape and Strip
$password = $_POST["mpass"]; # Get Password
$confirm_password =$_POST["mpwcheck"]; # Get Confirm Password
$email = $mysqli->real_escape_string($_POST["memail"]);
$captcha = $mysqli->real_escape_string($_POST["g-recaptcha-response"]);
$birth = "1990-01-01";
$ip = getRealIpAddr();
$secretkey = "YOUR PRIVATE SITE KEY HERE";
if(empty($captcha)){
echo ("<div class="content"><div class="contentbg registerbg"></div><div class="body_register"><div class="alert alert-danger"><b>Error:</b> Please fill in the correct ReCAPTCHA code!<br/><a href="?base=main&page=register" class="areg">« Go Back</a></div></div></div>");
} else {
$select_user_result = $mysqli->query("SELECT id FROM accounts WHERE name='".$username."' OR email='".$email."' LIMIT 1");
$returned = $select_user_result->num_rows;
if ($returned > 0) {
echo ("<div class="alert alert-danger"><b>Error:</b> This username or email is already used!<br/><a href="?base=main&page=register">« Go Back</a>");
} else if ($password != $confirm_password) {
echo ("<div class="alert alert-danger">Passwords didn't match!<br/><a href="?base=main&page=register">« Go Back</a></div></div></div>");
} else if (strlen($password) < 4 || strlen($password) > 12) {
echo ("<div class="alert alert-danger">Your password must be between 4-12 characters<br/><a href="?base=main&page=register">« Go Back</a>");
} else if (strlen($username) < 4 || strlen($username) > 12) {
echo ("<div class="alert alert-danger">Your username must be between 4-12 characters<br/><a href="?base=main&page=register">« Go Back</a>");
} else if (!strstr($email, '@')) {
echo ("<div class="alert alert-danger">You have filled in a wrong email address<br/><a href="?base=main&page=register">« Go Back</a>");
} else {
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretkey."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response.success==true)
{
//All data is ok
$password = sha1($password);
$insert_user_query = "INSERT INTO accounts (`name`, `password`, `ip`, `email`, `birthday`) VALUES ('".$username."', '".$password."', '".$ip."', '".$email."', '".$birth."')";
$mysqli->query($insert_user_query);
echo"
<div class="alert alert-success"><b>Success!</b> Please login, and head to the downloads page to get started!</div>
";
}
}
}
}
}
?>
Step 4 : Changing Public/Secret Keys Now that we have replaced the script, we are ready to change the ReCAPTCHA keys (both public and secret) that we created in Step 1.
First navigate to line 30 within the script and place your PUBLIC key where it says "YOUR SITE KEY HERE"
Now go to line 40 and edit where it says "YOUR SECRET SITE KEY" with your SECRET key.
Just save and refresh the register page, and it should work flawlessly!
Credits : greenelfx (for
You must be registered to see links
)
Last edited: