本文整理汇总了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;
}
}
}
}