{"id":835,"date":"2024-06-30T15:42:59","date_gmt":"2024-06-30T15:42:59","guid":{"rendered":"https:\/\/www.cmsgalaxy.com\/blog\/?p=835"},"modified":"2024-06-30T15:55:43","modified_gmt":"2024-06-30T15:55:43","slug":"how-to-reset-admin-password-in-drupal","status":"publish","type":"post","link":"https:\/\/www.cmsgalaxy.com\/blog\/how-to-reset-admin-password-in-drupal\/","title":{"rendered":"How to Reset admin password in Drupal?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">How to Reset admin password in Drupal\u00a07?<\/h2>\n\n\n\n<p>Drupal 7 stores a salted sha512 hash.<\/p>\n\n\n\n<p>You can always use the user_hash_password(\u2018mypassword\u2019) function (located in includes\/password.inc) to make yourself a new one, then paste it into the database.<\/p>\n\n\n\n<p>Create File on the root of Drupal run this file then you get the drupal&nbsp;hash password in Drupal 7 then go to your database and find user table then update the hash password.<\/p>\n\n\n\n<p>Password is:- 123456<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n\r\ndefine('DRUPAL_ROOT', getcwd());\r\nrequire_once DRUPAL_ROOT . '\/includes\/bootstrap.inc';\r\ndrupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);\r\nrequire_once 'includes\/password.inc';\r\necho user_hash_password('123456');\r\ndie();\r\nmenu_execute_active_handler();\r\n\r\n?><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Method 1: Using Drush (Drupal Shell)<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Install Drush if not already installed\r\n# Refer to Drush installation documentation for details\r\n\r\n# Open your terminal or command prompt\r\n# Navigate to your Drupal site's root directory\r\n\r\n# Reset the admin password using Drush\r\ndrush upwd admin --password=\"newpassword\"\r\n\nReplace admin with your username and newpassword with the new password.<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Method 2: Using MySQL Command Line<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Open your terminal or command prompt\r\n# Access your MySQL database\r\nmysql -u db_username -p\r\nReplace db_username with your MySQL username.\n\n# Select your Drupal database\r\nUSE database_name;\r\nReplace database_name with your Drupal database name.\n\n# Update the admin user's password\r\nUPDATE users SET pass = md5('newpassword') WHERE name = 'admin';\r\nReplace newpassword with your new password and admin with your username if different.\n\n# Exit MySQL\r\nEXIT;\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Method 3: Using PHP Script<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\ndefine('DRUPAL_ROOT', getcwd());\r\nrequire_once DRUPAL_ROOT . '\/includes\/bootstrap.inc';\r\ndrupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);\r\n\r\n$new_password = 'newpassword';\r\n$account = user_load_by_name('admin');\r\n$account->pass = user_hash_password($new_password);\r\nuser_save($account);\r\necho 'Password has been updated.';\r\n?>\r\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a new PHP file in your Drupal root directory (e.g., <code>reset_password.php<\/code>).<\/li>\n\n\n\n<li>Replace <code>newpassword<\/code> with your new password and <code>admin<\/code> with your username if different.<\/li>\n\n\n\n<li>Open your browser and navigate to the script (e.g., <code>http:\/\/yourdomain.com\/reset_password.php<\/code>).<\/li>\n\n\n\n<li>You should see a message saying &#8220;Password has been updated.&#8221;<\/li>\n\n\n\n<li>Delete the script after use for security reasons.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Method 4: Using the Password Reset Link<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to the Drupal login page (<code>http:\/\/yourdomain.com\/user\/login<\/code>).<\/li>\n\n\n\n<li>Click on the &#8220;Request new password&#8221; tab.<\/li>\n\n\n\n<li>Enter the username or email address associated with the admin account.<\/li>\n\n\n\n<li>Follow the instructions sent to the email to reset your password.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>How to Reset admin password in Drupal\u00a07? Drupal 7 stores a salted sha512 hash. You can always use the user_hash_password(\u2018mypassword\u2019)<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-835","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/comments?post=835"}],"version-history":[{"count":3,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/835\/revisions"}],"predecessor-version":[{"id":839,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/835\/revisions\/839"}],"wp:attachment":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/media?parent=835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/categories?post=835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/tags?post=835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}