<?php /** * PHP Loginform Example */ require '../src/HtpasswdGenerator.php'; $auth = new HtpasswdGenerator("secure/.htpasswd"); session_start(); if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') { $username = isset($_POST['username']) ? $_POST['username'] : null; $password = isset($_POST['password']) ? $_POST['password'] : null; if ($auth->isValid($username, $password)) { $_SESSION['user'] = $username; } else { die('Incorrect username or password<br /><a href="loginform.php">back</a>'); } } else { if (isset($_REQUEST['logout'])) { session_destroy(); die('Logout successfull<br /><a href="loginform.php">back</a>'); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
/** * @covers HtpasswdGenerator::isValid * @group publicMethods */ public function testIsValid() { $this->object->setUser("testuser1", '$apr1$70crho1l$tuUp8v81nAPPbIMkAOehn1'); $this->assertEquals(true, $this->object->isValid("testuser1", "123456")); }