-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
53 lines (44 loc) · 1.54 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
// Declaring global variables
$username = "";
$password = "";
echo 'Current php version: ' . phpversion();
// Requesting form input
if ($_SERVER['REQUEST_METHOD'] == "POST") {
if (isset($_POST['username'], $_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
// Password encryption
$options = [
'cost' => 12,
'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
];
$hash = password_hash($password, PASSWORD_BCRYPT, $options);
// Parameters for registration
$params = array(":username"=>$username,
":password"=>$hash
);
}
}
try {
$db = new PDO('mysql:host=localhost; dbname=test', 'root', 'root');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$sql = $db->prepare("INSERT INTO gebruiker (username, password) VALUES(:username, :password)");
$sql->execute($params);
} catch (PDOException $ex) {
echo $ex . "Error";
}
?>
<html>
<body>
<!-- Normal input -->
<fieldset> Normal Input
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<input type="text" placeholder="username" name="username" required>
<input type="password" placeholder="password" name="password" required>
<input type="submit" value="POST" name="submit">
</form>
</fieldset>
</body>
</html>