There are many cases of losing admin password, or simply forgetting the password. Maybe it’s because I haven’t logged in for a long time and forgot. Sometimes people hack the website and change the admin password. However, the problem will not be difficult to solve if you still have access to your hosting. But even if you can’t access the hosting, ask the provider to reset it, it doesn’t belong to you anyway.
There are two easiest ways for you to get your admin account back: one is in MySQL, the other is by inserting code into the function.php file . Here I will guide you both ways.
Change admin password in MySQL
To change the admin password in MySQL, you must login to the hosting admin page. Next go to MySQL management and login. This information you must know, if you do not remember the database login password of the website, you can view it in the file wp-config.php .
Then, you open the website’s Database, go to the wp_user table . Some websites use a prefix other than wp , as long as you choose the correct user table.
Then find the admin account, click edit it. You will see that the user_pass column is a confusing string of characters. Of course, because the password is encrypted.
Now you will change this value to the following sequence of characters: $P$BN/Ukn4jQ4Xm0YDKT9h/I8YFrNdRZw0
This is the encoded character sequence of the word “admin”. That is, now the admin account password has been changed to “admin”. You login to the website with this password, then remember to change it again.

Add an admin account for the website
The second way is to use the code inserted into the function.php file to create a new admin account for the website. Open the function file and insert the following code.
function addadmin(){
$user = 'admin2';
$pass = 'matkhau';
$email = 'email-cua-ban@domain.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}
add_action('init','addadmin');
<div>
<span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span><span>8</span><span>9</span><span>10</span><span>11</span><span>12</span><span>13</span><span>14</span><span>15</span><span>16</span><span>17</span><span>18</span><span>19</span><span>20</span><span>21</span>
</div>
Remember to change the user information, password, email above as you like. Then save this function.php file and proceed to log in to the website with the account you just created. Then you change the password of the main admin account or you can delete it and keep the new account, it’s up to you. But note that after regaining admin rights, you must delete the code just added to the function.php file .
summary
Forgetting the admin password or losing the admin account is not worrisome, just afraid of losing data. Above are 2 extremely simple ways for you to regain your admin rights. Good luck!

