Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Include database connection and functions here.
- include 'db_connect.php';
- include 'functions.php';
- // The hashed password from the form
- $password = $_POST['p'];
- // Create a random salt
- $random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
- // Create salted password (Careful with the chilli)
- $password = hash('sha512', $password.$random_salt);
- $username = $mysqli->real_escape_string($_POST['username']);
- $email = $mysqli->real_escape_string($_POST['email']);
- $stmt = $mysqli->prepare("SELECT * FROM members WHERE username = ? LIMIT 1");
- $stmt->bind_param('s', $username);
- $stmt->execute(); // Execute the prepared query.
- $stmt->store_result();
- if($stmt->num_rows == 1) {
- header("Location: '......?registrationfailed=1'");
- }
- else
- {
- if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password, salt) VALUES (?, ?, ?, ?)"))
- {
- $insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt);
- // Execute the prepared query.
- $insert_stmt->execute();
- header("Location: '......?success=1'");
- }
- else
- {
- header("Location: '......?registrationfailed=1'");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement