Ok there is one problem though. If a user is not already registered to a wordpress site with their email, the BrowserID login will fail, because it looks for the corresponding email in the wordpress database. Upon not finding it, it gives a “fail” error message.
In order to make the user experience more smooth, it would be a very very good idea to register a user who attempts to login to the wordpress site for the first time using BrowserID, if they are not already registered, in order to avoid a “fail” error message which in the end obliges them to register to the wordpress site anyway.
So in order to get around this obstacle, I added a few lines of code to the plugin, I added an “else” condition in the function “Login_by_email()” which registers a new user with a random password and using the first part of the email address as username, when this email is not yet registered to the wordpress website:
// Login user using e-mail address
function Login_by_email($email, $rememberme) {
global $user;
$user = null;
$userdata = get_user_by('email', $email);
if ($userdata) {
$user = new WP_User($userdata->ID);
wp_set_current_user($userdata->ID, $userdata->user_login);
wp_set_auth_cookie($userdata->ID, $rememberme);
do_action('wp_login', $userdata->user_login);
}
else{
$random_password = wp_generate_password(12, false);
$user_name= explode("@",$email);
wp_create_user($user_name[0], $random_password, $email);
$user = self::Login_by_email($email, $rememberme);
}
return $user;
}