From 71a047573ad3e093a0f47d386fbb154078989640 Mon Sep 17 00:00:00 2001 From: Miteruzo Date: Thu, 13 Jul 2023 00:49:52 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- create_user.php | 9 +++++++-- modules/user.mod.php | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/create_user.php b/create_user.php index 396150a..87f5cf4 100644 --- a/create_user.php +++ b/create_user.php @@ -5,8 +5,13 @@ require_once './db_connection.php'; require_once './modules/user.mod.php'; +$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+-./:;<=>?@[\]^_`~'; + $user = new User; + $user -> name = $_GET['name']; -$user -> pass = $_GET['pass']; -$user -> insert (); +$user -> pass = implode ( + array_map (fn () => $chars[rand (0, strlen ($chars) - 1)], range (1, 8))); + +echo [$user -> insert () -> id]; diff --git a/modules/user.mod.php b/modules/user.mod.php index 4edb82e..a5be820 100644 --- a/modules/user.mod.php +++ b/modules/user.mod.php @@ -31,5 +31,21 @@ User return $self; } + + public function + insert (): + Self + { + $sql = " + INSERT INTO + users (name, pass) + VALUES ('{$this -> name}', '{$this -> pass}')"; + $GLOBALS['__db_connection'] -> query ($sql) + or die ("db_insert error $sql"); + + $this -> id = $GLOBALS['__db_connection'] -> insert_id; + + return $this; + } }