· 9 years ago · Jan 31, 2017, 12:26 AM
1<?php
2 $dsn = 'mysql:host=localhost;dbname=dbname';
3 $username = 'username';
4 $password = 'password';
5 $hashOptions = [
6 'cost' => 10,
7 ];
8
9 $email = $_GET['email'];
10 $userlogin = $_GET['username'];
11 $userpass = $_GET['password'];
12 $hash = $_GET['hash'];
13
14 $secretKey = 'secretkey';
15
16 $createdHash = md5($email . $userlogin . $userpass . $secretKey);
17
18 if ($createdHash == $hash)
19 {
20 try
21 {
22 $dbh = new PDO($dsn, $username, $password);
23 $hashedpass = password_hash($userpass, PASSWORD_DEFAULT, $hashOptions);
24
25 $statement = $dbh->prepare ("INSERT INTO users (username, password, creationdate, email) values (:username, :hashedpass, NOW(), :email);");
26 $statement->bindParam(':username', $userlogin);
27 $statement->bindParam(':hashedpass', $hashedpass);
28 $statement->bindParam(':email', $email);
29
30 $statement->execute();
31 }
32 catch (PDOException $e)
33 {
34 echo "Error: " . $e->getMessage() . "<br/>";
35 die ();
36 }
37 }
38?>