示例#1
0
/**
 * Authenticate the user using the username and password.
 *
 * @since 0.0.1
 *
 * @param HQ_User|HQ_Error|null $user     HQ_User or HQ_Error object from a previous callback. Default null.
 * @param string                $username Username for authentication.
 * @param string                $password Password for authentication.
 * @return HQ_User|HQ_Error HQ_User on success, HQ_Error on failure.
 */
function hq_authenticate_username_password($user, $username, $password)
{
    if ($user instanceof HQ_User) {
        return $user;
    }
    if (empty($username) || empty($password)) {
        if (is_hq_error($user)) {
            return $user;
        }
        $error = new HQ_Error();
        if (empty($username)) {
            $error->add('empty_username', __('<strong>ERROR</strong>: The username field is empty.'));
        }
        if (empty($password)) {
            $error->add('empty_password', __('<strong>ERROR</strong>: The password field is empty.'));
        }
        return $error;
    }
    $user = get_user_by('login', $username);
    if (!$user) {
        return new HQ_Error('invalid_username', sprintf(__('<strong>ERROR</strong>: Invalid username. <a href="%s">Lost your password?</a>'), hq_lostpassword_url()));
    }
    /**
     * Filter whether the given user can be authenticated with the provided $password.
     *
     * @since 0.0.1
     *
     * @param HQ_User|HQ_Error $user     HQ_User or HQ_Error object if a previous
     *                                   callback failed authentication.
     * @param string           $password Password to check against the user.
     */
    $user = apply_filters('hq_authenticate_user', $user, $password);
    if (is_hq_error($user)) {
        return $user;
    }
    if (!hq_check_password($password, $user->user_pass, $user->ID)) {
        return new HQ_Error('incorrect_password', sprintf(__('<strong>ERROR</strong>: The password you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s">Lost your password?</a>'), $username, hq_lostpassword_url()));
    }
    return $user;
}
示例#2
0
</form>

<?php 
        if (!$interim_login) {
            ?>
<p id="nav">
<?php 
            if (!isset($_GET['checkemail']) || !in_array($_GET['checkemail'], array('confirm', 'nehqass'))) {
                if (get_option('users_can_register')) {
                    $registration_url = sprintf('<a href="%s">%s</a>', esc_url(hq_registration_url()), __('Register'));
                    /** This filter is documented in hq-includes/general-template.php */
                    echo apply_filters('register', $registration_url) . ' | ';
                }
                ?>
	<a href="<?php 
                echo esc_url(hq_lostpassword_url());
                ?>
" title="<?php 
                esc_attr_e('Password Lost and Found');
                ?>
"><?php 
                _e('Lost your password?');
                ?>
</a>
<?php 
            }
            ?>
</p>
<?php 
        }
        ?>