$avatar = $_FILES['avatar']['type']; $allowed = array('image/gif', 'image/png', 'image/jpg', 'image/jpeg'); if (!in_array($avatar, $allowed)) { $url = "register.php"; $_SESSION['errors'] = ['message' => "Avatar images must be JPG, PNG or GIF"]; header('Location: ' . $url); } } if ($password != $password2 || !validPass($password)) { $url = "register.php"; $_SESSION['errors'] = ['message' => "Passwords should be at least 8 characters long and consist of at least one lowercase letter, one uppercase letter, a number (0-9) and a special character."]; header('Location: ' . $url); } if (!validUser($username)) { $url = "register.php"; $_SESSION['errors'] = ['message' => "Usernames can only consist of a-Z and _ (underscore) OR a user already exists with that name"]; header('Location: ' . $url); } if ($password == $password2 && validUser($username) && validPass($password)) { Insert($username, $password); LogIn($username, $password); $url = "frontPage.php"; $_SESSION['errors'] = ['message' => 'Success! Thank you for registering.']; header('Location: ' . $url); } echo 'Noooo'; } else { $url = "register.php"; $_SESSION['errors'] = ['message' => "Something went wrong, please try again."]; header('Location: ' . $url); }
// loop through letters for ($i = 0; $i < strlen($pass); $i++) { $char = substr($pass, $i, 1); // if pair, count it and reset $lastChar if ($char == $lastChar) { $pairs++; $lastChar = null; } else { $lastChar = $char; } } // if 2+ pairs, true if ($pairs >= 2) { return true; } return false; } // function to check for a valid password function validPass($pass) { return hasTriplet($pass) & allLegalLetters($pass) & hasPairs($pass); } // get current password $pass = file_get_contents('input/day-11.txt'); // increment until we find a valid pass $pass = incrementPass($pass); while (!validPass($pass)) { $pass = incrementPass($pass); } // output answer echo 'Answer: ' . $pass;