if (isset($_POST['login'])) { // Checks email field for the legal characters if (empty($_POST["email"])) { $emailError = "Email is required"; } else { $email = to_store($_POST["email"]); if (!preg_match("/([\\w\\-]+\\@[\\w\\-]+\\.[\\w\\-]+)/", $email)) { $emailError = "Email format incorrect"; $email = ""; } } // Checks password field for entry if (empty($_POST["password"])) { $pswError = "Password is required"; } else { $psw = to_store($_POST["password"]); } // Checks all fields for entry if (!($email == '') && !($psw == '')) { // Applying query to retrieve the user's information from the database $stmt = $conn->prepare("SELECT * FROM Representatives where email = '{$email}'"); $stmt->execute(); $result = $stmt->fetch(); // Stores the information for the user in new variables $getDigest = $result['password_digest']; $getSalt = $result['salt']; $loginSalt = $psw . $getSalt; // Concatenates the password entered with the salt in the database $digestLogin = md5($loginSalt); // Performs a message digest function on the concatenation and assigns it to new variable // Comparing the new password digest with the one stored in the database
} else { $yearsError = "Enter interger values between 0 and 50"; $years = ""; } } // Checks password field for entry if (empty($_POST["password1"])) { $pswError = "Password is required"; } else { $psw = to_store($_POST["password1"]); } // Checks password field for entry if (empty($_POST["password2"])) { $psw1Error = "Password is required"; } else { $psw1 = to_store($_POST["password2"]); } // Checks all fields for entry if (!($firstname == '') && !($lastname == '') && !($constituency == '') && !($email == '') && !($years == '') && !($psw == '') && !($psw1 == '')) { // Compares both passwords if (!(strcmp($psw, $psw1) == 0)) { echo "Passwords don't match"; $psw = ""; // Clears the password field if they don't match $psw1 = ""; } else { $pswMatch = $psw; // Assigns password to a new variable $randNum = mt_rand(); // Assigns a random number to a new variable $digestRand = $pswMatch . $randNum;