forked from getnamingo/bind9-api-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_user.php
More file actions
37 lines (29 loc) · 1.02 KB
/
create_user.php
File metadata and controls
37 lines (29 loc) · 1.02 KB
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
<?php
require 'vendor/autoload.php';
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
try {
$dsn = "sqlite:{$_ENV['DB_DATABASE']}";
$pdo = new PDO($dsn, null, null, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
$username = 'testuser';
$password = 'securepassword';
$hashedPassword = password_hash($password, PASSWORD_ARGON2ID, [
'memory_cost' => 1<<17, // 128 MB
'time_cost' => 4, // Number of iterations
'threads' => 2 // Parallelism (CPU cores)
]);
$stmt = $pdo->prepare('INSERT INTO users (username, password) VALUES (:username, :password)');
$stmt->execute([
':username' => $username,
':password' => $hashedPassword,
]);
echo "User '$username' created successfully." . PHP_EOL;
} catch (PDOException $e) {
echo 'Database error: ' . $e->getMessage();
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}