本文整理匯總了PHP中UserDAO::userExists方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserDAO::userExists方法的具體用法?PHP UserDAO::userExists怎麽用?PHP UserDAO::userExists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UserDAO
的用法示例。
在下文中一共展示了UserDAO::userExists方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: login
/**
* Attempts to login with username and password.
*
* @param string $username Username
* @param string $password Password
* @return bool True if login was successful, or false otherwise.
*/
public function login($username, $password)
{
$dao = new UserDAO();
if ($dao->userExists($username)) {
$pwhash = $dao->getPassword($username);
if (pw_verify($password, $pwhash)) {
$this->loggedIn = true;
$this->username = $username;
return true;
}
}
return false;
}
示例2: password
$passwd2 = $_POST['passwd2'];
$username = $_POST['username'];
// validate password and username
if ($passwd != $passwd2) {
$warnings[] = "Passwords don't match";
}
if (!isValidPassword($passwd)) {
$warnings[] = "Not a valid password (longer than " . MIN_PASSWORD_LENGTH . " characters required)";
}
if (!isValidUsername($username)) {
$warnings[] = "Not a valid username (longer than " . MIN_USERNAME_LENGTH . " characters required)";
}
// No warnings means everything is in order, and we can create the user
if (count($warnings) == 0) {
$dao = new UserDAO();
if ($dao->userExists($username)) {
$warnings[] = "Username already taken";
} else {
$passwd = pw_encode($passwd);
if (!$dao->createUser($username, $passwd)) {
$warnings[] = "Failed to insert to database";
} else {
// Registration was successful, redirect the user to
// the login screen
$session->set('register_flag', true);
header("Location: login.php");
exit;
}
}
}
}