/** * @expectedException WrongStateException */ public function testCookieCollection() { if (!isset($_SERVER["DOCUMENT_ROOT"]) || !$_SERVER["DOCUMENT_ROOT"]) { $this->markTestSkipped('can\'t test cookies without web'); } echo ""; CookieCollection::create()->add(Cookie::create('anotherTestCookie')->setValue('testValue')->setMaxAge(60 * 60))->httpSetAll(); }
public static function attempt($array, $remember = false) { //Table::show(self::$hashedFields); // $hashed = array(); // foreach ($array as $key => $value) { if (Table::contains(self::$hashedFields, $key)) { Table::add($hashed, Hash::make($array[$key]), $key); } } // //Table::show($hashed); // $where = ""; $ok = false; // $i = 0; foreach ($array as $key => $value) { if ($i > 0) { $where .= " and "; } if (Table::contains(self::$hashedFields, $key)) { $where .= "{$key}='" . $hashed[$key] . "' "; } else { $where .= "{$key}='{$value}' "; } $i++; } $sql = "select * from " . self::$table . " where " . $where; //echo $sql; // if (Database::countS($sql) > 0) { //returning true value $ok = true; // // session $user = Database::read($sql); $saved = Config::get('auth.saved_fields'); // $static = array(); // foreach ($user[0] as $key => $value) { if (array_key_exists($key, $saved)) { $static[$key] = $value; } } // Session::put('auths', $static); // // remember cookie if ($remember) { Cookie::create(Config::get('auth.rememeber_cookie'), $user[0]["rememberToken"], time() + 3600 * 24 * 7); } } // return $ok; }
/** * @param RequestInterface $request * @param string $name * @param callable $modify * * @return RequestInterface */ public static function modify(RequestInterface $request, $name, $modify) { if (!is_callable($modify)) { throw new InvalidArgumentException('$modify must be callable.'); } $cookies = Cookies::fromRequest($request); $cookie = $modify($cookies->has($name) ? $cookies->get($name) : Cookie::create($name)); return $cookies->with($cookie)->renderIntoCookieHeader($request); }
function doRun() { $msg = ''; $username = mysql_real_escape_string($_POST['name']); $pass = mysql_real_escape_string($_POST['pass']); try { $db = new PDO('mysql:host=localhost;dbname=testData', 'root', 'root'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $db->prepare(' SELECT username, pass FROM testTable WHERE username = :name AND pass = :pass '); $stmt->bindParam(':name', $username, PDO::PARAM_STR); $stmt->bindParam(':pass', $pass, PDO::PARAM_STR); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); if ($result == false) { $msg = 'sorry could not connect'; } else { //$_SESSION['name'] = $username; /** * Create a cookie with the name "myCookieName" and value "testing cookie value" */ $cookie = new Cookie(); // Set cookie name $cookie->setName('Login'); // Set cookie value $cookie->setValue("testing cookie value"); // Set cookie expiration time $cookie->setTime("+1 hour"); // Create the cookie $cookie->create(); // Delete the cookie. //$cookie->delete(); $msg = 'logged in as ' . $username . '<br>'; } } catch (PDOException $e) { echo "Error:" . $e; } echo $msg; $db = NULL; }
public function provideGetsCookieByNameData() { return [['theme=light', 'theme', Cookie::create('theme', 'light')], ['theme=', 'theme', Cookie::create('theme')], ['hello=world; theme=light; sessionToken=abc123', 'theme', Cookie::create('theme', 'light')], ['hello=world; theme=; sessionToken=abc123', 'theme', Cookie::create('theme')]]; }
// Check to see if the user is already logged in if ($cookie_handler->cookie_exists("compsec")) { print "Error: Cannot log in if user is already logged in!"; } else { // Check to see if the user is already in the database. // The function will return an array if they are. $results = get_user_data($uuid); if (is_array($results)) { $uuid = $results[1]; $database_password = $results[2]; $salt = $results[3]; // Validate that the supplied password is correct $hashed_password = hash("sha512", $password . $salt); if ($database_password == $hashed_password) { // Store cookie on client's computer $cookie = Cookie::create($uuid, $hashed_password); $result = $cookie_handler->set_cookie("compsec", $cookie); if ($result == false) { print "An unexpected error has prevented you from logging in. Reason: Unable to create a login cookie."; } // Login successful update_last_login($uuid); header("location:index.php"); } else { print "Error: Invalid password. Press the back button to try again."; } } else { print "Error: User does not exist! Press the back button to try again."; } } ?>
public static function setDefault() { Cookie::create(self::getName(), Config::get('lang.default'), 60 * 24 * 7); Res::stsession("Fiesta_lang", Config::get('lang.default')); }
/** * @test */ public function it_sets_cookies() { $request = (new FigCookieTestingRequest())->withHeader(Cookies::COOKIE_HEADER, 'theme=light; sessionToken=RAPELCGRQ; hello=world'); $request = FigRequestCookies::set($request, Cookie::create('hello', 'WORLD!')); $this->assertEquals('theme=light; sessionToken=RAPELCGRQ; hello=WORLD%21', $request->getHeaderLine('Cookie')); }