使用
和
说明
// get user by login via the supplied username (form input)
$user = get_user_by(\'login\', $username);
//assign user ID based on user login name
$user_id = $user->ID;
// get user data by passing the assigned $user_id variable to get_userdata
// which returns the user object and a host of user related info to access
$user_data = get_userdata($user_id);
// assign the username and password to variables
$user_login = $user_data->user_login;
$user_pass = $user_data->user_pass;
// check the username/password against the submitted input values
if ($user_login = $username && $user_pass = $password) {
// do something...
注释
$username
默认情况下应验证true,否则如果
$username
提供的与数据库中已有的不匹配。因此,验证取决于
$password
存储用户提供的表单输入的变量。
通过缩短现有代码或使用其他API函数,可能有更有效的方法来实现这一点。
根据fdsa 你可以反过来使用wp_authenticate_username_password
以这种方式,
$auth = wp_authenticate_username_password($user, $username, $password);
if (!$auth->user_login = $username && !$auth->user_pass = $password) {
echo \'not authenticated\';
} else {
echo \'authenticated\';
}
但比这更好的是,
$auth = wp_authenticate_username_password($user, $username, $password);
if (is_wp_error($auth)) {
echo \'not authenticated\';
} else {
echo \'authenticated\';
}
真的,这个答案应该是肯定的
fdsa 最有效的方法是通过(遗憾的是)未记录的WP核心函数。
http://wpseek.com/wp_authenticate_username_password/