Example #1
0
$password = "";
$msg = "";
if (isset($_SESSION["isLoggedIn"])) {
    if ($_SESSION["isLoggedIn"] == true) {
        header('Location: account.php');
    }
}
$usernameValidator = new UsernameValidator();
$passwordValidator = new PasswordValidator();
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    if (isset($_POST['username'])) {
        $_SESSION['user'] = $_POST['username'];
        if ($usernameValidator->isValid($_SESSION['user'])) {
            if (isset($_POST['password'])) {
                $_SESSION['pass'] = $_POST['password'];
                if ($passwordValidator->isValid($_SESSION['pass'])) {
                    $_SESSION['isLoggedIn'] = true;
                    return header('Location: account.php');
                    exit;
                } else {
                    $msg = "Your password in Invalid";
                }
            }
        } else {
            $msg = "Your username is Invalid";
        }
    }
}
?>

Example #2
0
} else {
    if ($_SERVER['REQUEST_METHOD'] == "POST") {
        if (isset($_POST['username']) && isset($_POST['password'])) {
            $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 {
<?php

include_once "Validator.php";
class PasswordValidator extends Validator
{
    protected $pattern = "/^[a-zA-Z0-9!@#\$%^&*\\(\\)]{5,}\$/";
}
$passwordValidator = new PasswordValidator();
$passwordValidator->isValid($_SESSION["password"]);
Example #4
0
function isPasswordValid($password)
{
    $passwordValidator = new PasswordValidator();
    return $passwordValidator->isValid($password);
}
Example #5
0
$passCheck = new PasswordValidator();
$errorMan = new ErrorManager();
session_start();
$user = '';
$pass = '';
if (isset($_SESSION['username'])) {
    $userLogin->isLoggedIn();
}
if (isset($_POST['username'])) {
    $user = $_POST['username'];
}
if (isset($_POST['password'])) {
    $pass = $_POST['password'];
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if ($passCheck->isValid($pass)) {
        if ($userCheck->isValid($user)) {
            $_SESSION['username'] = $user;
            $userLogin->isLoggedIn();
        } else {
            $errorMan->addError($user, 'Invalid Username. Username should be 5 alphabetic characters.');
        }
    } elseif ($userCheck->isValid($user)) {
        $errorMan->addError($pass, 'Invalid Password. Password should be at least 5 alpha numeric characters.');
    } else {
        $errorMan->addError($user, 'Invalid Username. Username should be 5 alphabetic characters.');
        $errorMan->addError($pass, 'Invalid Password. Password should be at least 5 alpha numeric characters.');
    }
}
$msg1 = '';
$msg2 = '';
Example #6
0
<?php

require_once 'classes/initialize.php';
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 
Example #7
0
$username = '';
$password = '';
$errors = [];
$usernameValidator = new UsernameValidator();
$passwordValidator = new PasswordValidator();
if (isUserLoggedIn()) {
    header('Location: account.php');
    exit;
} else {
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $username = getParamUsername();
        $password = getParamPassword();
        if (!$usernameValidator->isValid($username)) {
            $errors['invaliduser'] = "******";
        }
        if (!$passwordValidator->isValid($password)) {
            $errors['invalidpassword'] = "******";
        }
        if (count($errors) == 0) {
            logInUser($username);
            header('Location: account.php');
            exit;
        }
    }
}
function logInUser($username)
{
    $_SESSION['username'] = $username;
}
function getParamUsername()
{