/** * @covers HtpasswdGenerator::getUsers * @covers HtpasswdGenerator::clearUsers * @covers HtpasswdGenerator::setUser * @group privateMethods */ public function testHelper() { $this->assertEquals(true, is_array($this->object->getUsers())); $this->object->clearUsers(); $this->assertEquals(0, count($this->object->getUsers())); $this->object->setUser("testuser1", '$apr1$70crho1l$tuUp8v81nAPPbIMkAOehn1'); $this->assertEquals(1, count($this->object->getUsers())); }
<?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">
<?php /** * Web Example * * @author Sven Kuegler <*****@*****.**> */ require '../src/HtpasswdGenerator.php'; $g = new HtpasswdGenerator("secure/.htpasswd"); $g->add("testuser1", "123456"); $g->add("testuser2", "123456"); $g->add("testuser3", "123456"); $g->delete("testuser2"); $g->add("testuser3", "newpassword"); echo "<pre>" . print_r($g, true) . "</pre>";
/** * Launch the protection activation or disactivation * * @param string $sUser HTPASSWD User * @param string $sPwd HTPASSWD Password * @return bool success of fail */ public function setRepositoryProtection($sUser, $sPwd) { require_once _PS_MODULE_DIR_ . 'prediggo/classes/HtpasswdGenerator.php'; $oHtpasswdGenerator = new HtpasswdGenerator($sUser, $sPwd, $this->sRepositoryPath); return $oHtpasswdGenerator->generate(); }