diff --git a/session/composer.json b/session/composer.json new file mode 100644 index 0000000..b7cf0fe --- /dev/null +++ b/session/composer.json @@ -0,0 +1,12 @@ +{ + "name": "violet/spies", + "type": "project", + "autoload": { + "psr-4": { + "Violet\\Spies\\": "src/" + } + }, + "require": { + "vlucas/phpdotenv": "^5.6" + } +} diff --git a/session/css/.gitkeep b/session/css/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/session/css/styles.css b/session/css/styles.css new file mode 100644 index 0000000..944041f --- /dev/null +++ b/session/css/styles.css @@ -0,0 +1,179 @@ +* { + margin: 0; + padding: 0; +} + +body { + /* Positioning */ + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + + /* Styling */ + background-color: #bbedbe; +} + +h1 { + /* Positioning */ + width: 100%; + padding: 2vw; + + /* Font */ + font-size: 6vw; + text-align: center; +} + +h3 { + font-size: 4vw; +} + +h5 { + font-size: 2vw; +} + +h1, +h3, +h5, +p, +input { + color: #0e3610; +} + + +#content { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + width: 100%; +} + +#account-content { + display: flex; + width: 80%; +} + +#account-content img { + width: 400px; + height: auto; +} + +#nav { + /* Form Shape */ + width: 100%; + padding: 0; + + /* Positioning */ + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; +} + +#update-pw { + /* Form Shape */ + width: 100%; + padding: 0; + + /* Positioning */ + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +form { + /* Form Shape */ + width: 60%; + padding: 2.5vw 5vw 2.5vw 5vw; + + /* Positioning */ + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +.row { + /* Row Shape */ + width: 100%; + display: flex; +} + +input { + /* Input Shape */ + width: 50%; + padding: 1vw; + margin: 1vw; + border: none; + border-radius: 18px; + + /* Styling */ + background-color: #f1fbf2; + + /* Font */ + font-size: 1vw; + font-weight: 400; +} + +button { + /* Button Shape */ + width: 60%; + padding: 1vw; + margin: 1vw; + border: none; + border-radius: 18px; + + /* Font */ + color: white; + font-size: 1vw; + font-weight: 600; + + /* Transition for hover */ + transition-duration: 500ms; + + background-color: #1c6b20; +} + +button:hover { + background-color: #26942D; +} + +table { + border-spacing: 0; + table-layout: fixed; + width: 40%; + border: 1px solid black; +} + +td { + margin: 0; + padding: 1vw; + border: 1px solid black; + text-align: center; +} + +.card { + padding: 2vw; + background-color: gray; + border-radius: 18px; +} + +.error { + color: white; + background-color: red; +} + +.success { + color: white; + background-color: #0e3610; +} + +.reset { + background-color: #cc0000; +} + +.reset:hover { + background-color: #FF0000; +} diff --git a/session/hidden.php b/session/hidden.php new file mode 100644 index 0000000..ac1eee6 --- /dev/null +++ b/session/hidden.php @@ -0,0 +1,71 @@ + 'roast', 'bob' => 'ross'); +$access = false; + +if (isset($_POST['username']) && isset($_POST['password'])) { + $username = $_POST['username']; + $password = $_POST['password']; + if (array_key_exists($username, $users) && $users[$username] === $password) + $access = true; +} + +$file = 'fbi.txt'; + +function fileRead($file) +{ + if (isset($_GET['fbi'])) + $file = 'fbi.txt'; + else + $file = 'spies.txt'; + if ($access) { + echo "reading $file"; + $fs = fopen($file, 'r'); + $string = fread($fs, filesize($file)); + $values = explode('||>><<||', $string); + + echo ''; + foreach ($values as $v) { + list($a, $b) = explode(',', $v); + + echo ' + + + + + '; + } + echo '
' . $a . '' . $b . '
'; + } else + header('Location: .?access=false'); +} +?> + + + + + Spies + + + + + +

View Confidential Information

+ +Access Granted

'; + + echo ' + + + '; + + fileRead($file); +} +?> + + + + + diff --git a/session/img/.gitkeep b/session/img/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/session/img/bob.jpg b/session/img/bob.jpg new file mode 100644 index 0000000..8720541 Binary files /dev/null and b/session/img/bob.jpg differ diff --git a/session/includes/account.php b/session/includes/account.php new file mode 100644 index 0000000..f450535 --- /dev/null +++ b/session/includes/account.php @@ -0,0 +1,27 @@ +Account'; + +if (isset($_POST['password1']) && isset($_POST['password2'])) { + if ($_POST['password1'] == $_POST['password2']) { + update_user_pw($_POST['password1']); + } else { + $_GET['error'] = true; + } +} + +echo '
+ +
+ + + +
+
'; +?> diff --git a/session/includes/fbi.txt b/session/includes/fbi.txt new file mode 100644 index 0000000..06a9203 --- /dev/null +++ b/session/includes/fbi.txt @@ -0,0 +1 @@ +skinner,gatekeeper||>><<||csm,alien||>><<||dana,skeptic||>><<||fox,believer \ No newline at end of file diff --git a/session/includes/functions.php b/session/includes/functions.php new file mode 100644 index 0000000..271cfb9 --- /dev/null +++ b/session/includes/functions.php @@ -0,0 +1,155 @@ +View Confidential Information'; + if ($_SESSION['access'] !== true) { + if (isset($_GET['error']) && $_GET['error'] === true) { + echo ' +
+
Access Denied.
+

Invalid username or password.

+
+ '; + } + echo ' +
+
+ + +
+
+ + +
+
+ '; + } else if (isset($_GET['file']) && isset($_SESSION['access'])) { + echo ' +
+
Access Granted.
+
+
+
+ + +
+
+ '; + fileRead($_GET['file']); + } +} + +function fileRead($file) +{ + $fs = fopen($file, 'r'); + $string = fread($fs, filesize($file)); + $values = explode('||>><<||', $string); + + echo ' + + + + + + '; + foreach ($values as $v) { + list($a, $b) = explode(',', $v); + + echo ' + + + + + '; + } + echo '
AgentCodename
' . ucfirst($a) . '' . ucwords($b) . '
'; +} + +function authUser() +{ + if (isset($_POST['username']) && isset($_POST['password'])) { + $username = $_POST['username']; + $password = $_POST['password']; + + // Connect to the DB + $conn = mysqli_connect(HOST, USER, PASS, DB); + + // Write a DB query + $sql = 'SELECT password FROM users WHERE username = "' . $username . ' ";'; + + // Run DB query + $results = mysqli_query($conn, $sql); + + if (mysqli_num_rows($results) == 0) { + $_GET['error'] = true; + } else { + $row = mysqli_fetch_assoc($results); + + if ($row['password'] == $password) { + $_SESSION['access'] = true; + $_GET['file'] = 'includes/fbi.txt'; + $_SESSION['username'] = $username; + } else { + $_GET['error'] = true; + } + } + } +} + +function get_user_image() +{ + // Connect to the DB + $conn = mysqli_connect(HOST, USER, PASS, DB); + + // Write a DB query + $sql = 'SELECT image_path FROM users WHERE username = "' . $_SESSION['username'] . ' ";'; + + // Run DB query + $results = mysqli_query($conn, $sql); + $row = mysqli_fetch_assoc($results); + + return $row['image_path']; +} + +function update_user_pw($password) +{ + // Connect to the DB + $conn = mysqli_connect(HOST, USER, PASS, DB); + + // Write a DB query + $sql = 'UPDATE users SET password = "' . $password . '" WHERE username = "' . $_SESSION['username'] . ' ";'; + + // Run DB query + $result = mysqli_query($conn, $sql); + if ($result) { + echo ' +
+
Password Updated!
+
'; + } else { + echo ' +
+
Password update failed!
+

Something went wrong in the server...

+
+ '; + } +} +?> diff --git a/session/includes/nav.php b/session/includes/nav.php new file mode 100644 index 0000000..4d87dcc --- /dev/null +++ b/session/includes/nav.php @@ -0,0 +1,24 @@ + + + + + ' . getLogoutButton() . ' + +'; + +function getLogoutButton() +{ + if ($_SESSION['access'] === true) + return ''; +} + +if (isset($_GET['logout'])) { + $_SESSION['access'] = false; + session_destroy(); + header('Location: .'); +} +?> diff --git a/session/includes/spies.txt b/session/includes/spies.txt new file mode 100644 index 0000000..d67c36a --- /dev/null +++ b/session/includes/spies.txt @@ -0,0 +1 @@ +dale,the government||>><<||bill,the barber||>><<||hank,the texan||>><<||boomhauer,the marshall \ No newline at end of file diff --git a/session/includes/video.php b/session/includes/video.php new file mode 100644 index 0000000..6f6c15f --- /dev/null +++ b/session/includes/video.php @@ -0,0 +1,11 @@ +YouTube Video'; +echo ' + +'; +?> diff --git a/session/index.php b/session/index.php new file mode 100644 index 0000000..fea5ca6 --- /dev/null +++ b/session/index.php @@ -0,0 +1,43 @@ +safeLoad(); + +include_once ('includes/functions.php'); +authUser(); +?> + + + + + Session + + + + + + +
+ +
+ + diff --git a/session/js/.gitkeep b/session/js/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/session/js/index.js b/session/js/index.js new file mode 100644 index 0000000..e69de29