Locked out of the Website

I was going through the features and accidentally clicked on change password, without even knowing what is the password for the future login. please help me!

  • Predrag Dubajic

    Hi Prachi,

    Hope you're doing well.

    Do you have access to your WP files via FTP or cPanel?
    If so you can create new admin account from there and use it to get back into your WP admin.

    To do this you will need to access your WP folder, navigate to themes folder and then the folder of your currently active theme.
    In there find the functions.php file and edit it.
    At the end of that file add this code:

    function add_admin_acct(){
    	$login = 'USERNAME';
    	$passw = 'PASSWORD';
    	$email = 'EMAIL';
    
    	if ( !username_exists( $login )  && !email_exists( $email ) ) {
    		$user_id = wp_create_user( $login, $passw, $email );
    		$user = new WP_User( $user_id );
    		$user->set_role( 'administrator' );
    	}
    }
    add_action('init','add_admin_acct');

    Just update the USERNAME, PASSWORD and EMAIL values to your desired ones, just make sure that USERNAME and EMAIL are not already used by an existing account on your site.

    Once that is done and you have saved the changes go and visit your site homepage, this will fire up the code and create new admin user.
    You can now remove the code from functions.php and you should be able to login with the new details that you just created.

    Hope this helps :slight_smile:

    Best regards,
    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.