From 0c00e55ac80df10c26adc39a83b135b11c6eafbe Mon Sep 17 00:00:00 2001
From: Ryan Torok <11rytorok3900@gmail.com>
Date: Thu, 21 Jun 2018 17:06:51 -0500
Subject: [PATCH] first commit: some account management files
---
.idea/misc.xml | 6 +
.idea/modules.xml | 8 +
.idea/paintbrush.org.iml | 8 +
.idea/sqldialects.xml | 6 +
.idea/vcs.xml | 6 +
.idea/workspace.xml | 345 ++++++++++++++++++++++++++++
public_html/acct/SaltRepeat.php | 14 ++
public_html/acct/changePassword.php | 40 ++++
public_html/acct/createAccount.php | 57 +++++
public_html/acct/getLocalSalt.php | 44 ++++
public_html/acct/login.php | 49 ++++
public_html/acct/testQuery.php | 39 ++++
public_html/acct/updateSerFile.php | 32 +++
public_html/index.php | 13 ++
14 files changed, 667 insertions(+)
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/paintbrush.org.iml
create mode 100644 .idea/sqldialects.xml
create mode 100644 .idea/vcs.xml
create mode 100644 .idea/workspace.xml
create mode 100644 public_html/acct/SaltRepeat.php
create mode 100644 public_html/acct/changePassword.php
create mode 100755 public_html/acct/createAccount.php
create mode 100644 public_html/acct/getLocalSalt.php
create mode 100755 public_html/acct/login.php
create mode 100644 public_html/acct/testQuery.php
create mode 100644 public_html/acct/updateSerFile.php
create mode 100755 public_html/index.php
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..28a804d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..67be7d1
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/paintbrush.org.iml b/.idea/paintbrush.org.iml
new file mode 100644
index 0000000..c956989
--- /dev/null
+++ b/.idea/paintbrush.org.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml
new file mode 100644
index 0000000..c85ae9a
--- /dev/null
+++ b/.idea/sqldialects.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..74d6f73
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,345 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ DEFINITION_ORDER
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1529459392777
+
+
+ 1529459392777
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public_html/acct/SaltRepeat.php b/public_html/acct/SaltRepeat.php
new file mode 100644
index 0000000..392a731
--- /dev/null
+++ b/public_html/acct/SaltRepeat.php
@@ -0,0 +1,14 @@
+connect_error) {
+ die("Connection failed: " . $connection->connect_error);
+}
+
+//echo $id;
+// prepare database update
+$stmt = $connection->prepare("UPDATE users SET password = ?, salt = ? WHERE id = ?");
+$stmt->bind_param("ssi", $hash, $salt, $id);
+$stmt->execute();
+$error = $connection->error;
+if (strlen($error) > 0) {
+ echo $error;
+} else {
+ if ($id == 0) {
+ echo "invalid id";
+ } else {
+ echo "done";
+ }
+}
diff --git a/public_html/acct/createAccount.php b/public_html/acct/createAccount.php
new file mode 100755
index 0000000..6896d2c
--- /dev/null
+++ b/public_html/acct/createAccount.php
@@ -0,0 +1,57 @@
+connect_error) {
+ die("Connection failed: " . $connection->connect_error);
+}
+
+//check validity of school code if there is one
+if (strlen($schoolCode) > 0) {
+
+ $stmt = $connection->prepare("SELECT schoolcode FROM users WHERE schoolcode = ? ;");
+ $stmt->bind_param("s", $schoolCode);
+ $stmt->execute();
+
+ $exists = false;
+ if ($fetch = $stmt->fetch()) {
+ $exists = true;
+ }
+
+ if (!$exists) {
+ die("badSC");
+ }
+} else {
+ $schoolCode = "0";
+}
+
+
+// prepare database insertion
+$stmt = $connection->prepare("INSERT INTO users VALUE (null, ?, ?, ?, ?, ?, ?, ?, null );");
+$stmt->bind_param("sssssss", $username, $hash, $salt, $first, $last, $email, $schoolCode);
+$stmt->execute();
+echo $connection->error;
+$result = $stmt->fetch();
+
+echo "done";
\ No newline at end of file
diff --git a/public_html/acct/getLocalSalt.php b/public_html/acct/getLocalSalt.php
new file mode 100644
index 0000000..ca65c82
--- /dev/null
+++ b/public_html/acct/getLocalSalt.php
@@ -0,0 +1,44 @@
+connect_error) {
+ die("Connection failed: " . $connection->connect_error);
+}
+
+// get the user's salt
+
+$stmt = $connection->prepare("SELECT salt FROM users WHERE username = ?");
+$stmt->bind_param("s", $username);
+$stmt->execute();
+$result = $stmt->get_result();
+$atLeastOne = false;
+while ($row = $result->fetch_row()) {
+ $atLeastOne = true;
+ echo $row[0] . "\n";
+}
+
+if (!$atLeastOne) {
+ //output a random string of characters, to hide that the username doesn't exist
+ try {
+ echo base64_encode(random_bytes(random_int(45, 65))) . "\n";
+ } catch (Exception $e) {
+ }
+}
+
+echo $connection->error;
+
diff --git a/public_html/acct/login.php b/public_html/acct/login.php
new file mode 100755
index 0000000..4225e20
--- /dev/null
+++ b/public_html/acct/login.php
@@ -0,0 +1,49 @@
+connect_error) {
+ die("Connection failed!");
+}
+
+$stmt = $connection->prepare("SELECT * FROM users WHERE username = ?");
+$stmt->bind_param("s", $username);
+$stmt->execute();
+
+
+$allResults = $stmt->get_result();
+while($result = $allResults->fetch_row()) {
+ //verify password
+ $encryptedPassword = $result[2]; //password
+ $match = password_verify($passwordAttempt, $encryptedPassword);
+ if ($match) {
+ echo $result[0] . " "; //id
+ //get the rest of the user details
+ if ($needFile == "true") {
+ $serFile = $result[8];
+ if (strlen($serFile) == 0)
+ echo "true";
+ else
+ echo $serFile;
+ } else {
+ echo "true";
+ }
+ echo "\n";
+ }
+}
\ No newline at end of file
diff --git a/public_html/acct/testQuery.php b/public_html/acct/testQuery.php
new file mode 100644
index 0000000..e8ac2e6
--- /dev/null
+++ b/public_html/acct/testQuery.php
@@ -0,0 +1,39 @@
+connect_error) {
+ die("Connection failed: " . $connection->connect_error);
+}
+
+try {
+ $bytes = random_bytes(50);
+} catch (Exception $e) {
+}
+echo $bytes . "
";
+
+// do a test query
+$stmt = $connection->prepare("INSERT INTO users VALUE (null, 'test4', 'pass', ?, 'first', 'last', 'email', '0', null );");
+$stmt->bind_param("s", $bytes);
+$stmt->execute();
+
+//$stmt = $connection->prepare("SELECT 1,2,3 FROM dual;");
+$stmt = $connection->prepare("SELECT salt FROM users WHERE username = 'test4' ;");
+$stmt->execute();
+$result = $stmt->get_result();
+$row = $result->fetch_row();
+echo $row[0] . "
";
+
+echo $bytes == $row[0];
+
diff --git a/public_html/acct/updateSerFile.php b/public_html/acct/updateSerFile.php
new file mode 100644
index 0000000..7acf32d
--- /dev/null
+++ b/public_html/acct/updateSerFile.php
@@ -0,0 +1,32 @@
+connect_error) {
+ die("Connection failed: " . $connection->connect_error);
+}
+
+
+// prepare database update
+$stmt = $connection->prepare("UPDATE users SET userData = ? WHERE id = ?");
+$stmt->bind_param("si", $serFile, $id);
+$stmt->execute();
+$error = $connection->error;
+if (strlen($error) > 0) {
+ echo $error . "\n";
+}
+echo "done";
diff --git a/public_html/index.php b/public_html/index.php
new file mode 100755
index 0000000..f264b3f
--- /dev/null
+++ b/public_html/index.php
@@ -0,0 +1,13 @@
+This is php output
');
+
+?>
+
+
+
+ Paintbrush LMS Home Page
+
+
+ This is a web server used for the function of the Paintbrush LMS client program. Please visit our home page for more information.
+
+