Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'DB-connect.php';
- $error = 0;
- $valueUsername = mysqli_real_escape_string($link, $_POST['username']);
- $valuePassword = mysqli_real_escape_string($link, $_POST['password']);
- $valueeMail = mysqli_real_escape_string($link, $_POST['email']);
- $valueRealName = mysqli_real_escape_string($link, $_POST['realname']);
- $valueAge = mysqli_real_escape_string($link, $_POST['age']);
- $usernameQuery = "SELECT username FROM accounts WHERE username='$valueUsername'";
- $checkUsername = mysqli_query($link, $usernameQuery);
- if(0 < mysqli_num_rows($checkUsername))
- {
- echo '<script>alert("That username has already been used.");</script>';
- $error++;
- }
- if(0 === preg_match("/\S+/", $_POST['username']))
- {
- echo '<script>alert("Your username is invalid.");</script>';
- $error++;
- }
- if(0 === preg_match("/.{10,}/", $_POST['password']))
- {
- echo '<script>alert("The password entered was invalid. (Too short)");</script>';
- $error++;
- }
- if(0 === preg_match("/\S+/", $_POST['realname']))
- {
- echo '<script>alert("Please enter a real name.");</script>';
- $error++;
- }
- if (0 === preg_match("/.+@.+\..+/", $_POST['email']))
- {
- echo '<script>alert("Invalid e-mail.");</script>';
- }
- $emailQuery="SELECT email FROM accounts WHERE email='$valueeMail'";
- $checkEmail = mysqli_query($link, $emailQuery);
- if(0 < mysqli_num_rows($checkEmail))
- {
- echo '<script>alert("That e-mail has already been used.");</script>';
- $error++;
- }
- if(0 === preg_match("/\S+/", $_POST['age']))
- {
- echo '<script>alert("Please enter your age.");</script>';
- $error++;
- }
- function unique_salt() {
- return substr(sha1(mt_rand()),0,22);
- }
- $uniqueSalt = unique_salt();
- function myhash($valuePassword, $uniqueSalt)
- {
- $hash = sha1($uniqueSalt . $valuePassword);
- for ($i = 0; $i < 1000; $i++)
- {
- $hash = sha1($hash);
- }
- return $hash;
- }
- $hash = myhash($valuePassword, $uniqueSalt);
- if ($error<1)
- {
- $sql = "INSERT INTO accounts (username, password, Salt, email, realname, age) VALUES ('$valueUsername', '$hash', '$uniqueSalt', '$valueeMail', '$valueRealName', '$valueAge')";
- }
- if (!mysqli_query($link, $sql))
- {
- die('Error: ' . mysqli_error($link));
- }
- if ($error<1)
- {
- header("refresh:1; url= include/login.php");
- echo '<h1 style="text-align: center; font-weight:600;">Account created,</h1><h2 style="text-align: center;"> redirecting to login-page in a few seconds...</h2>';
- }
- else if ($error>0)
- {
- echo '<script>alert("You are missing something, try again!");</script>';
- header("refresh:0; url= include/registration.php");
- }
- mysqli_close($link);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement