Created
January 31, 2017 00:23
-
-
Save CloudyWater/0a53b1a0c1a9cfb49646e7977445b1b4 to your computer and use it in GitHub Desktop.
AddUser.php using PDO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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