Skip to content
Permalink
3481a87158
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
38 lines (31 sloc) 1.09 KB
<?php
defined('APP_DIR') or define('APP_DIR', 'app/');
include_once('app/config/config.php');
include_once('app/database/Database.php');
include_once('app/model/User.php');
$dbh = new PDO('mysql:host=' . Config::db_host, Config::db_user, Config::db_pass);
/* Create database if it doesn't exist */
$dbh->exec('CREATE DATABASE IF NOT EXISTS ' . Config::db_name);
/* Connect to database */
$dbh = Database::connect();
/* Create users table if it doesn't exist */
$stmt = 'CREATE TABLE IF NOT EXISTS users (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(32) NOT NULL,
password VARCHAR(64) NOT NULL,
access VARCHAR(8) NOT NULL,
login_attempts INT(6) UNSIGNED NOT NULL
)';
$dbh->exec($stmt);
/* Create user and admin if they don't exist */
$user = new User;
$user->username = 'user';
$user->password = password_hash('userpass', PASSWORD_DEFAULT);
$user->access = 'user';
$user->save();
$user = new User;
$user->username = 'admin';
$user->password = password_hash('adminpass', PASSWORD_DEFAULT);
$user->access = 'admin';
$user->save();
?>