Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- db_common.php
- <?php
- // These variables define the connection information for your MySQL database
- $username = "";
- $password = "";
- $host = "localhost";
- $dbname = "";
- try
- {
- $db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
- }
- catch(PDOException $ex)
- {
- die("Failed to connect to the database: " . $ex->getMessage());
- }
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
- if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
- {
- function undo_magic_quotes_gpc(&$array)
- {
- foreach($array as &$value)
- {
- if(is_array($value))
- {
- undo_magic_quotes_gpc($value);
- }
- else
- {
- $value = stripslashes($value);
- }
- }
- }
- undo_magic_quotes_gpc($_POST);
- undo_magic_quotes_gpc($_GET);
- undo_magic_quotes_gpc($_COOKIE);
- }
- header('Content-Type: text/html; charset=utf-8');
- session_start();
- db_functions.php
- <?php
- require("db_common.php");
- function xzuser_register($cp_user, $pass, $domain, $email) {
- $query = "
- SELECT
- 1
- FROM users
- WHERE
- username = :username
- ";
- $query_params = array(
- ':username' => $cp_user
- );
- try
- {
- $stmt = $db->prepare($query);
- $result = $stmt->execute($query_params);
- }
- catch(PDOException $ex)
- {
- die("Failed to run query: " . $ex->getMessage());
- }
- $row = $stmt->fetch();
- if($row)
- {
- die("This username is already in use");
- }
- $query = "
- SELECT
- 1
- FROM users
- WHERE
- email = :email
- ";
- $query_params = array(
- ':email' => $email
- );
- try
- {
- $stmt = $db->prepare($query);
- $result = $stmt->execute($query_params);
- }
- catch(PDOException $ex)
- {
- die("Failed to run query: " . $ex->getMessage());
- }
- $row = $stmt->fetch();
- if($row)
- {
- die("This email address is already registered");
- }
- $query = "
- INSERT INTO users (
- username,
- password,
- salt,
- email
- ) VALUES (
- :username,
- :password,
- :salt,
- :email
- )
- ";
- $salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
- $password = hash('sha256', $pass . $salt);
- for($round = 0; $round < 65536; $round++)
- {
- $password = hash('sha256', $password . $salt);
- }
- $query_params = array(
- ':username' => $username,
- ':password' => $password,
- ':salt' => $salt,
- ':email' => $email
- );
- try
- {
- $stmt = $db->prepare($query);
- $result = $stmt->execute($query_params);
- }
- catch(PDOException $ex)
- {
- die("Failed to run query: " . $ex->getMessage());
- }
- header("Location: login.php");
- die("Redirecting to login.php");
- }
- ?>
- test.php
- <?php
- require("includes/db_functions.php");
- xzuser_register("test234", "test123", "justtesting2.com", "willh@test.com");
- ?>
Add Comment
Please, Sign In to add comment