Code:
<?php
$ip = "127.0.0.1";
$sqluser = "root";
$sqlpw = "";
$userdb = "newproject_db_auth";
//Save PW in plain text? yes = on, no = off
$plain = "no";
$salt = "phoohie1yaihooyaequae7PuiWoeNgahjieth3ru3yeeghaepahb7aeYaipe2we6zii6mai6uweig8siasheinoungeoyeiLohShi2xoh2xi8ooxee9ahpiehahc9Phe";
function clean_str($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
$str = mysql_real_escape_string($str);
$str = preg_replace("/[^a-zA-Z0-9@.]/" , "" , $str);
return $str;
}
If (isset($_POST['username']))
{
if (empty($_POST['username']) OR empty($_POST['password']) OR empty($_POST['password2']) OR empty($_POST['email']))
{
echo "Error! One or more fields are empty. You'll be redirected in 5 seconds... Or click ";
?>
<a href="register.php">here.</a>
<script type="text/javascript">
setTimeout("location.href='register.php'",5000);
</script>
<?php
die;
}
$user = htmlspecialchars(clean_str($_POST['username']));
$pass = htmlspecialchars(clean_str($_POST['password']));
$pass2 = htmlspecialchars(clean_str($_POST['password2']));
$email = htmlspecialchars(clean_str($_POST['email']));
If ($pass != $pass2)
{
echo "Error! Password 1 and Password 2 are not the same. You'll be redirected in 5 seconds... Or click ";
?>
<a href="register.php">here.</a>
<script type="text/javascript">
setTimeout("location.href='register.php'",5000);
</script>
<?php
die;
}
$conn = new mysqli($ip,$sqluser,$sqlpw,$userdb);
if (mysqli_connect_errno() == 0)
{
$qusr = "SELECT * FROM bg_user WHERE user_id = '".$user."';";
$resusr = $conn->query($qusr);
If ($resusr->num_rows > 0)
{
echo "Error! Username is in use. You'll be redirected in 5 seconds... Or click ";
?>
<a href="register.php">here.</a>
<script type="text/javascript">
setTimeout("location.href='register.php'",5000);
</script>
<?php
die;
}
$qmail = "SELECT * FROM bg_user WHERE email = '$email'";
$mailres = $conn->query($qmail);
if ($mailres->num_rows > 0)
{
echo "Error! Email is in use. You'll be redirected in 5 seconds... Or click ";
?>
<a href="register.php">here.</a>
<script type="text/javascript">
setTimeout("location.href='register.php'",5000);
</script>
<?php
die;
}
$realpass = hash("sha256",$user.$salt.$pass);
If ($plain == "no")
{
$insertusr = "INSERT INTO bg_user (user_id, passwd, email) VALUES (?, ?, ?)";
$qInsert = $conn->prepare ($insertusr);
$qInsert->bind_param("sss",$user,$realpass,$email);
$qInsert->execute();
if ($qInsert->affected_rows == 1)
{
echo "Success! Your Account is ready, Have Fun. :) You'll be redirected in 5 seconds... Or click ";
?>
<a href="register.php">here.</a>
<script type="text/javascript">
setTimeout("location.href='register.php'",5000);
</script>
<?php
die;
}
Else;
{
echo "Error! Please contact an Administrator!!! You'll be redirected in 5 seconds... Or click ";
die;
?>
<a href="register.php">here.</a>
<?php
}
}
ElseIf ($plain == "yes");
{
$insertusr = "INSERT INTO bg_user (user_id, truepasswd, passwd, email) VALUES (?, ?, ?, ?)";
$qInsert = $conn->prepare ($insertusr);
$qInsert->bind_param("ssss",$user,$pass,$realpass,$email);
$qInsert->execute();
if ($qInsert->affected_rows == 1)
{
echo "Success! Your Account is ready, Have Fun. :) You'll be redirected in 5 seconds... Or click ";
?>
<a href="register.php">here.</a>
<script type="text/javascript">
setTimeout("location.href='register.php'",5000);
</script>
<?php
die;
}
Else;
{
echo "Error! Please contact an Administrator!!! You'll be redirected in 5 seconds... Or click ";
?>
<a href="register.php">here.</a>
<script type="text/javascript">
setTimeout("location.href='register.php'",5000);
</script>
die;
<?php
}
}
}
}
Else;
{
echo '<form method="post" action="register.php">
Username:<br>
<input type="text" size="24" maxlength="12" name="username"</input><br>
Password:<br>
<input type="password" size="24" maxlength="12"
name="password"><br>
Password (again):<br>
<input type="password" size="24" maxlength="12"
name="password2"><br>
Email:
<br>
<input type="text" size="24" maxlength="50"
name="email"><br><br>
<input type="submit" value="Register">
</form>';
}
echo "<font color='red' size='2'>Register Script by Sentence'</font>";
?>