From 2f3c8f73908a9df23a88e1014365a481973c2457 Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Fri, 9 Nov 2018 15:58:00 +0100 Subject: [PATCH] installation add user via class --- cont/adduser.php | 10 ++++++---- install/adduser.php | 10 ++++++---- php/classes.user.php | 20 ++++++++++++++++++++ php/edit-user.php | 8 +++++++- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/cont/adduser.php b/cont/adduser.php index 7945db7..1934912 100644 --- a/cont/adduser.php +++ b/cont/adduser.php @@ -1,12 +1,14 @@ -

Benutzer hinzufügen

-
- - + + + +
+ + diff --git a/install/adduser.php b/install/adduser.php index 7945db7..1934912 100644 --- a/install/adduser.php +++ b/install/adduser.php @@ -1,12 +1,14 @@ -

Benutzer hinzufügen

-
- - + + + +
+ + diff --git a/php/classes.user.php b/php/classes.user.php index cd89b33..1391ca4 100644 --- a/php/classes.user.php +++ b/php/classes.user.php @@ -32,5 +32,25 @@ print_r("1"); } } + + function new($uname, $password){ + session_start(); + include $_SESSION["docroot"].'/php/connect.php'; + include $_SESSION["docroot"].'/php/hash.php'; + + $query = "SELECT `uid` FROM `users` WHERE `username` = '$uname'"; + $result = $mysqli->query($query); + if($result->num_rows==0){ + $salt = create_salt(); + $passhash = hash_password($password, $salt); + $query = "INSERT INTO `users` (`username`, `password`, `salt`, `last_login`) VALUES ('$uname', '$passhash', '$salt', CURRENT_TIMESTAMP);"; + $result = $mysqli->query($query); + unset($salt); + unset($password); + print_r(0); + } + else{print_r(1);} + $mysqli->close(); + } } ?> diff --git a/php/edit-user.php b/php/edit-user.php index 48c4f5f..4729fee 100644 --- a/php/edit-user.php +++ b/php/edit-user.php @@ -2,13 +2,19 @@ session_start(); include $_SESSION["docroot"].'/php/classes.user.php'; $user = new user; - $user->get_info($_COOKIE["token"]); + if($_POST["function"]!="new-user"){ + $user->get_info($_COOKIE["token"]); + } switch ($_POST["function"]) { case 'change-pw': $user->change_password($_POST["current"], $_POST["new"]); break; + case 'new-user': + $user->new($_POST["username"], $_POST["passwd"]); + break; + default: // code... break;