query("SELECT count(*) as c from users")[0]["c"]; if ($intUserCount < 1) Respond::redirect("/user/register"); if (Request::posts("username", "password")) { $strUsername = Request::getPosted("username"); $strPassword = Request::getPosted("password"); $strHash = sha1($strPassword); $varUsers = $c->query( "SELECT * from users where username like ? and hash = ?", $strUsername, $strHash); if (count($varUsers) !== 1) throw new Exception("Zero or more than one user returned for credentials provided"); $strToken = sha1(microtime()); $c->query( "INSERT into sessions (username, token) values (?, ?)", $strUsername, $strToken); Cookie::set("token", $strToken); BootstrapRender::message( "Successfully signed in", "info"); Respond::redirect("/user/info"); } } catch (Exception $x) { BootstrapRender::message($x->getMessage(), "danger"); } ?>