本文整理汇总了PHP中PasswordHash::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP PasswordHash::validate方法的具体用法?PHP PasswordHash::validate怎么用?PHP PasswordHash::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PasswordHash
的用法示例。
在下文中一共展示了PasswordHash::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build_backend_subactions
function build_backend_subactions()
{
global $backend_subactions, $pluginpages_handlers;
$backend_subactions = url_action_subactions(array("_index" => url_action_alias(array("login")), "index" => url_action_alias(array("login")), "_prelude" => function (&$data, $url_now, &$url_next) {
global $ratatoeskr_settings, $admin_grp, $ste, $languages;
if ($admin_grp === NULL) {
$admin_grp = Group::by_name("admins");
}
$ste->vars["all_languages"] = array();
$ste->vars["all_langcodes"] = array();
foreach ($languages as $code => $data) {
$ste->vars["all_languages"][$code] = $data["language"];
$ste->vars["all_langcodes"][] = $code;
}
ksort($ste->vars["all_languages"]);
sort($ste->vars["all_langcodes"]);
/* Check authentification */
if (isset($_SESSION["ratatoeskr_uid"])) {
try {
$user = User::by_id($_SESSION["ratatoeskr_uid"]);
if ($user->pwhash == $_SESSION["ratatoeskr_pwhash"] and $user->member_of($admin_grp)) {
if (empty($user->language)) {
$user->language = $ratatoeskr_settings["default_language"];
$user->save();
}
load_language($user->language);
if ($url_next[0] == "login") {
$url_next = array("content", "write");
}
$data["user"] = $user;
$ste->vars["user"] = array("id" => $user->get_id(), "name" => $user->username, "lang" => $user->language);
return;
/* Authentification successful, continue */
} else {
unset($_SESSION["ratatoeskr_uid"]);
}
} catch (DoesNotExistError $e) {
unset($_SESSION["ratatoeskr_uid"]);
}
}
load_language();
/* If we are here, user is not logged in... */
$url_next = array("login");
}, "login" => url_action_simple(function ($data) {
global $ste, $admin_grp;
if (!empty($_POST["user"])) {
try {
$user = User::by_name($_POST["user"]);
if (!PasswordHash::validate($_POST["password"], $user->pwhash)) {
throw new Exception();
}
if (!$user->member_of($admin_grp)) {
throw new Exception();
}
/* Login successful. */
$_SESSION["ratatoeskr_uid"] = $user->get_id();
$_SESSION["ratatoeskr_pwhash"] = $user->pwhash;
load_language($user->language);
$data["user"] = $user;
$ste->vars["user"] = array("id" => $user->get_id(), "name" => $user->username, "lang" => $user->language);
} catch (Exception $e) {
$ste->vars["login_failed"] = True;
}
if (isset($data["user"])) {
throw new Redirect(array("content", "write"));
}
}
echo $ste->exectemplate("/systemtemplates/backend_login.html");
}), "logout" => url_action_simple(function ($data) {
unset($_SESSION["ratatoeskr_uid"]);
unset($_SESSION["ratatoeskr_pwhash"]);
load_language();
throw new Redirect(array("login"));
}), "content" => url_action_subactions(array("write" => function (&$data, $url_now, &$url_next) {
global $ste, $translation, $textprocessors, $ratatoeskr_settings, $languages, $articleeditor_plugins;
list($article, $editlang) = array_slice($url_next, 0);
if (!isset($editlang)) {
$editlang = $data["user"]->language;
}
if (isset($article)) {
$ste->vars["article_editurl"] = urlencode($article) . "/" . urlencode($editlang);
} else {
$ste->vars["article_editurl"] = "";
}
$url_next = array();
$default_section = Section::by_id($ratatoeskr_settings["default_section"]);
$ste->vars["section"] = "content";
$ste->vars["submenu"] = isset($article) ? "articles" : "newarticle";
$ste->vars["textprocessors"] = array();
foreach ($textprocessors as $txtproc => $properties) {
if ($properties[1]) {
$ste->vars["textprocessors"][] = $txtproc;
}
}
$ste->vars["sections"] = array();
foreach (Section::all() as $section) {
$ste->vars["sections"][] = $section->name;
}
$ste->vars["article_section"] = $default_section->name;
/* Check Form */
//.........这里部分代码省略.........
示例2: url_action_simple
}, "_notfound" => url_action_simple(function ($data) {
header("HTTP/1.1 404 Not Found");
header("Content-Type: text/plain");
echo "404 Not Found\nThe resource \"{$_SERVER["REQUEST_URI"]}\" could not be found.\n";
}), "_index" => url_action_alias(array("index")), "index" => function (&$data, $url_now, &$url_next) {
global $ste;
$url_next = array();
$ste->vars["menu"] = "home";
$latest = Package::latest();
echo package_list($latest, "Latest Packages");
}, "login" => function (&$data, $url_now, &$url_next) {
global $ste, $user;
if ($user === NULL and isset($_POST["login"])) {
try {
$user = User::by_name($_POST["username"]);
if (PasswordHash::validate($_POST["password"], $user->pwhash)) {
$ste->vars["success"] = "Logged in successfully.";
$_SESSION["r7r_repo_login_name"] = $user->get_name();
$url_next = array("_prelude", "index");
} else {
$user = NULL;
$ste->vars["error"] = "Username / Password wrong.";
$url_next = array("index");
}
} catch (DoesNotExistError $e) {
$user = NULL;
$ste->vars["error"] = "Username / Password wrong.";
$url_next = array("index");
}
} else {
$url_next = array("index");