summary refs log tree commit diff stats
path: root/mysql-php/code/a2.php
diff options
context:
space:
mode:
authorSudipto Mallick <smlckz@termux-alpine>2024-02-03 16:29:27 +0000
committerSudipto Mallick <smlckz@termux-alpine>2024-02-03 16:29:27 +0000
commite031215516573b14545e81665b991176a467bce5 (patch)
treec35521ae8c4b22cff29bb58f633a639541ca99d2 /mysql-php/code/a2.php
parent15ff931b72b24a8f7f1d06d0549d985162a1d6b6 (diff)
downloadzadania-e031215516573b14545e81665b991176a467bce5.tar.gz
Implement PHP assignment #3, improve the rest
Diffstat (limited to 'mysql-php/code/a2.php')
-rw-r--r--mysql-php/code/a2.php13
1 files changed, 6 insertions, 7 deletions
diff --git a/mysql-php/code/a2.php b/mysql-php/code/a2.php
index 10a7a33..9d9a1a5 100644
--- a/mysql-php/code/a2.php
+++ b/mysql-php/code/a2.php
@@ -1,7 +1,7 @@
 <?php
 declare(strict_types=1);
 error_reporting(E_ALL);
-// student: name roll city email date_of_birth
+
 function connect_to_database() {
     mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
     if (!($dbh = mysqli_connect('localhost', 'root', '')))
@@ -32,8 +32,7 @@ function connect_to_database() {
 }
 
 function check_credentials($dbh, $username, $password) {
-    if (!isset($username) || empty($username) || !isset($password) || empty($password)) 
-        return false;
+    if (empty($username) || empty($password)) return false;
     $stmt = mysqli_prepare($dbh, 'SELECT `PASSWORD` FROM `LOGIN` WHERE `USERNAME` = ?');
     mysqli_stmt_bind_param($stmt, 's', $username);
     mysqli_stmt_execute($stmt);
@@ -44,17 +43,17 @@ function check_credentials($dbh, $username, $password) {
 }
 
 function update_credentials($dbh) {
-    if (!check_credentials($dbh, $_POST['previous_username'], $_POST['previous_password']))
+    if (!check_credentials($dbh, @$_POST['previous_username'], @$_POST['previous_password']))
         display_failure('Can not update credentials, both previous usernames and passwords need to be provided and they need to be valid.');
     $new_username = null;
     $new_password = null;
     $successful = [];
-    if (isset($_POST['new_username']) && !empty($_POST['new_username']))
+    if (!empty($_POST['new_username']))
         $new_username = $_POST['new_username'];
-    if (isset($_POST['new_password']) && !empty($_POST['new_password']))
+    if (!empty($_POST['new_password']))
         $new_password = $_POST['new_password'];
     if ($new_password !== null) {
-        if (!isset($_POST['new_password2']) || empty($_POST['new_password2']))
+        if (empty($_POST['new_password2']))
             display_failure('Need to provide new password twice');
         if ($new_password !== $_POST['new_password2'])
             display_failure('New password provided twice need to match');