I would like for my users to be able to login just by entering their username without password and without 2 factor authentification (no registration possible)
I know it’s not good practice, but access to the website will be only possible from a specific location so there is no security issue.
I have found the following code here
// First get the user details
$user = get_user_by('login', $username );
// If no error received, set the WP Cookie
if ( !is_wp_error( $user ) )
{
wp_clear_auth_cookie();
wp_set_current_user ( $user->ID ); // Set the current user detail
wp_set_auth_cookie ( $user->ID ); // Set auth details in cookie
$message = "Logged in successfully";
} else {
$message = "Failed to log in";
}
echo $message;
But i have no idea how and where to implement.
Could i just give everybody the same dummy password and fill it automatically/hidden? Again security is not an issue here, we just want the user to log in to track activity later.
3
Answers
I finally managed to do what i was looking for! Thanks a lot for your help.
Here is the final code:
The code is not perfect but it will do the work! Thanks again!
you can use this code
I can tell you how to login via URL (not exactly what you want, but you may find it useful).
Place the following code at the very beginning of functions.php (you can find it in your theme folder), right after "<?php":
Login URL => https://SITENAME.XXX/wp-admin?username=XXXXX&pass=XXXXX
Please note you can choose where users will be directed.