示例#1
0
<?php

include_once 'myincludes.php';
$username = "";
$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";
        }
    }
示例#2
0
文件: index.php 项目: jtsurfrat/login
require_once 'initializer.php';
$user_log = new UserLogin();
$message = '';
$error = ['Invalid password', 'Invalid username', "Invalid username and password"];
// $hasError = new ErrorManager();
if (isset($_SESSION['username']) && strlen($_SESSION['username']) > 0) {
    if ($user_log->isLogged()) {
        header('Location: account.php');
        exit;
    }
} 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;
示例#3
0
function isUsernameValid($username)
{
    $usernameValidator = new UsernameValidator();
    return $usernameValidator->isValid($username);
}
示例#4
0
<?php

require_once 'initialize.php';
$userLogin = new LoginOptions();
$userCheck = new UsernameValidator();
$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.');
示例#5
0
文件: index.php 项目: bebaps/sessions
<?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 
示例#6
0
<?php

require_once 'classes/MyIncludes.php';
$msg = '';
$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)
{
<?php

include_once "Validator.php";
class UsernameValidator extends Validator
{
    protected $pattern = "/^[a-zA-Z]{5,}\$/";
}
$usernameValidator = new UsernameValidator();
$usernameValidator->isValid($_SESSION["user"]);