WordPress Login without Database Access

If you have no access to your WordPress backend and no phpMyAdmin to change your MD5 Password Hash… here is a simple and fast solution. Please note: You need a FTP connection to your server.

Open your theme functions.php and add the following code to create a new user with administrator role:

function wpb_admin_account(){
    $user = 'USERNAME';
    $pass = 'PASSWORD';
    $email = 'USER@MAIL.COM';

    if (!username_exists($user)  && !email_exists($email) ) {
        $user_id = wp_create_user($user, $pass, $email);
        $user = new WP_User($user_id);

add_action('init', 'wpb_admin_account');