$username = $_POST['username']; $password = $_POST['password']; $usernameValidator = new UsernameValidator(); $passwordValidator = new PasswordValidator(); // if()){ // // if(!(strlen($username) > 5)){ // echo "dog"; // $user_log->startSession(); // // } // } else { // echo "error username is invalid"; // } if ($passwordValidator->isValid($password) && $usernameValidator->isValid($username)) { // if(strlen($_POST['password']) > 7){ $_SESSION['username'] = $_POST['username']; $user_log->startSession(); header('Location: account.php'); exit; // } } else { if (!$passwordValidator->isValid($password)) { // $message = $error[0]; $message = $error[0]; } else { if (!$usernameValidator->isValid($username)) { // $message = $error[1]; $message = $error[1]; } else { if (!$usernameValidator->isValid($username) && !$passwordValidator->isValid($password)) { // $message = $error[2]; // $message = $error[2];
if (isset($_SESSION['username'])) { header('Location: account.php'); } $usernameValidator = new UsernameValidator(); $passwordValidator = new PasswordValidator(); $errorManager = new ErrorManager(); $userLogin = new UserLogin(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!$usernameValidator->isValid($_POST['username'])) { $errorManager->addError('username', 'Please enter a valid username'); } if (!$passwordValidator->isValid($_POST['password'])) { $errorManager->addError('password', 'Please enter a valid password'); } if (!$errorManager->hasErrors()) { $userLogin->startSession($_POST['username']); header('Location: account.php'); exit; } } require_once 'header.php'; ?> <form action="index.php" method="POST"> <div> <label>Username:</label> <input type="text" name="username" value="" placeholder="Enter Username"> <span class="error"><?php echo $errorManager->getError('username'); ?> </span>