Skip to content

Instantly share code, notes, and snippets.

@CloudyWater
Created January 31, 2017 00:23
Show Gist options
  • Save CloudyWater/0a53b1a0c1a9cfb49646e7977445b1b4 to your computer and use it in GitHub Desktop.
Save CloudyWater/0a53b1a0c1a9cfb49646e7977445b1b4 to your computer and use it in GitHub Desktop.
AddUser.php using PDO
<?php
$dsn = 'mysql:host=localhost;dbname=dbname';
$username = 'username';
$password = 'password';
$hashOptions = [
'cost' => 10,
];
$email = $_GET['email'];
$userlogin = $_GET['username'];
$userpass = $_GET['password'];
$hash = $_GET['hash'];
$secretKey = 'secretkey';
$createdHash = md5($email . $userlogin . $userpass . $secretKey);
if ($createdHash == $hash)
{
try
{
$dbh = new PDO($dsn, $username, $password);
$hashedpass = password_hash($userpass, PASSWORD_DEFAULT, $hashOptions);
$statement = $dbh->prepare ("INSERT INTO users (username, password, creationdate, email) values (:username, :hashedpass, NOW(), :email);");
$statement->bindParam(':username', $userlogin);
$statement->bindParam(':hashedpass', $hashedpass);
$statement->bindParam(':email', $email);
$statement->execute();
}
catch (PDOException $e)
{
echo "Error: " . $e->getMessage() . "<br/>";
die ();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment