40 lines
1.0 KiB
PHP
40 lines
1.0 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* /setup/002-createAdmin.php
|
||
|
* @version 1.0
|
||
|
* @desc Create an admin account with login credintials
|
||
|
* @author Fándly Gergő Zoltán
|
||
|
* @copy 2017 Fándly Gergő Zoltán
|
||
|
*/
|
||
|
|
||
|
header("Content-type: text/plain; charset=UTF-8");
|
||
|
require_once("../config/config.php");
|
||
|
|
||
|
if(!isset($_GET['password'])){
|
||
|
echo "Plese set a password with GET 'password'!";
|
||
|
flush();
|
||
|
exit();
|
||
|
}
|
||
|
else{
|
||
|
echo "Generating password...\n";
|
||
|
flush();
|
||
|
$passwd=$_GET['password'];
|
||
|
echo "Password generated!\n";
|
||
|
flush();
|
||
|
echo "Encrypting password...\n";
|
||
|
flush();
|
||
|
$enc=\Defuse\Crypto\Crypto::encrypt($passwd, $crypto);
|
||
|
echo "Encription done!\n";
|
||
|
echo "Populating database...\n";
|
||
|
$sql=$db->prepare("INSERT INTO users (name, accesslevel, password) VALUES (:name, :accesslevel, :password)");
|
||
|
$sql->execute(array(":name"=>"Admin", ":accesslevel"=>3, ":password"=>$enc));
|
||
|
$id=$db->lastInsertId();
|
||
|
echo "Done!\n\n";
|
||
|
flush();
|
||
|
echo "Credintials:\n>username: ".$id."\n>password: ".$passwd;
|
||
|
flush();
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
?>
|