• Resolved catmaniax

    (@catmaniax)


    Hello!

    I’d like to ask you if there’s a way to have a prohibited username (admin in my case) so people cannot use my admin name through my frontend modal, but that I can still be able to login only through the backend (wp-login.php).

    I use the plugin “Keyy”, it’s like CLEF if you remember it, so I want to only be able to login through that as admin and all my users to login through the frontend.

    I put my admin username to the prohibited usernames in Cerber, but it affects Keyy thus I could not login, so I deleted the username from the list for now.

    Please let me know.
    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author gioni

    (@gioni)

    As of now there is no such a way. It’s kinda weird feature.

    Thread Starter catmaniax

    (@catmaniax)

    Not weird at all, if it lets you bypass the 2FA and be able to login as an admin instantly through the frontend.

    Plugin Author gioni

    (@gioni)

    It’s the same as this: https://wordpress.org/support/topic/web-url-transmitted-in-block-notification-emails/

    I mean having a custom login URL just for one account (having a special one for admin). The answer: hiding stuff (like pretending that site is not running WP) will not be implemented.

    Thread Starter catmaniax

    (@catmaniax)

    Ok, thanks for the reply.

    Thread Starter catmaniax

    (@catmaniax)

    Hey!

    I bring this thread back again, to show a working solution I got from Keyy’s author, so admins can no longer login through the frontend, as it should be in my opinion.

    Here’s the snippet:

    <?php
    
    add_action('authenticate', 'keyy_block_front_end_admin_logins', 999, 3 );
    
    function keyy_block_front_end_admin_logins($user, $username, $password) {
    	
    	if (is_a($user, 'WP_User') && $user->has_cap('manage_options') && !is_backend_login()) {
    
    		return new WP_Error( 'failed', __( "Admins cant login from the front end", "keyy"));
    	}
    
    	return $user;
    }
    
    function is_backend_login(){
        $path = str_replace(array('\\','/'), DIRECTORY_SEPARATOR, ABSPATH);
        return (in_array($path.'wp-login.php', get_included_files()) || $GLOBALS['pagenow'] === 'wp-login.php' || $_SERVER['PHP_SELF']== '/wp-login.php');
    }

    I’d like to hear your feedback on this!
    Thanks.

    • This reply was modified 8 years, 1 month ago by catmaniax.
    Thread Starter catmaniax

    (@catmaniax)

    @gioni

    I also noticed that the above solution works with other frontend login plugins as well.

    I’d really like your input for this method and opinion for that code though 🙂

    Plugin Author gioni

    (@gioni)

    I’m sorry for the delayed response. So, this code is OK and can be used along with WP Cerber with no issue. But this code should be used as a code snippet. Having two different login pages is a big deal for an average user/blogger and a real pain in the neck for a plugin author because people forget even their single Custom login URL. So WP Cerber will never provide functionality like this. Probably it will be implemented as an add-on that can be downloaded and installed manually.

    Thread Starter catmaniax

    (@catmaniax)

    Thanks for the reply 🙂

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Allow Prohibited username only on wp-login.php’ is closed to new replies.