From ca784b878869279c95deaaadb754f17646e172dc Mon Sep 17 00:00:00 2001 From: Neku Date: Sun, 15 Dec 2013 10:17:54 +0100 Subject: some changes --- moe/includes/api.php | 23 +++++++++++++++++++++++ moe/includes/core.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 moe/includes/api.php create mode 100644 moe/includes/core.php (limited to 'moe/includes') diff --git a/moe/includes/api.php b/moe/includes/api.php new file mode 100644 index 0000000..da0d652 --- /dev/null +++ b/moe/includes/api.php @@ -0,0 +1,23 @@ + \ No newline at end of file diff --git a/moe/includes/core.php b/moe/includes/core.php new file mode 100644 index 0000000..59d6d4e --- /dev/null +++ b/moe/includes/core.php @@ -0,0 +1,36 @@ + "SET NAMES 'UTF8'")); + +function register ($email, $pass) { + global $db; + $do = $db->prepare("SELECT email FROM accounts WHERE email = (:email)"); + $do->bindParam(':email', $email); + $do->execute(); + $result = $do->fetch(); + if($result['email'] === $email){ + header('Location: ../register/index.html#fail'); + }else{ + $do = $db->prepare("INSERT INTO accounts (email, pass) VALUES (:email, :pass)"); + $do->bindParam(':email', $email); + $hash = password_hash($pass, PASSWORD_DEFAULT); + $do->bindParam(':pass', $hash); + $do->execute(); + header('Location: api.php?do=cp'); + } +} + +function login ($email, $pass) { + global $db; + $do = $db->prepare("SELECT pass FROM accounts WHERE email = (:email)"); + $do->bindParam(':email', $email); + $do->execute(); + $result = $do->fetch(PDO::FETCH_ASSOC); + + if (password_verify($pass, $result['pass'])) { + header('Location: api.php?do=cp'); + }else{ + header('Location: ../login/index.html#fail'); + } +} +?> \ No newline at end of file -- cgit v1.2.3