Khôi phục password cho Drupal 7 bằng Drush

Khôi phục password cho Drupal 7 bằng Drush

Sometimes, whether in testing or other situations, you need to reset a password (often the admin password) for a Drupal site.

Edit: The shortest answer is that two wonderful options are built into drush!

# Get an admin login link
drush uli
# Set the password for any user
drush upwd admin --password="newpassword"

The latest versions of drush have drush uliwhich just gives you a one-time login link for admin.

$ drush uli
http://default/user/reset/1/1311169130/gf-1uDYC51jONONNF-jq3_ciKfLqhE93SsS9YNAnaEY

Unfortunately it doesn't get the hostname right in most cases (probably there's no way to know it if base_url is not set) so you have to change "default" correct hostname.

So in the case above, I would paste the link into a browser and then change it to

http://example.com/user/reset/1/1311169130/gf-1uDYC51jONONNF-jq3_ciKfLqhE93SsS9YNAnaEY

Now for the long version

In Drupal 6, you could just reset the admin password with:

cd <drupal_root_directory>
drush sql-cli   # or mysql -u<user> -p<pass> <drupal_db>
update users set name='admin', pass=md5('drupal');

and then log in with username 'admin' and password 'drupal'.

But no more. Drupal 7 has a unique hash for each site, which means you can't just use the md5() trick any more. However, there is a script in the scripts directory that will do this.

cd <drupal root directory>
php scripts/password-hash.sh 'drupal'

Now copy the resultant hash and paste it into the query:

drush sql-cli
update users set name='admin', pass='pasted_big_hash_from_above' where uid=1;
quit
Bạn thấy bài viết này như thế nào?: 
Average: 5 (1 vote)
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Bình luận (0)

 

Add Comment

Filtered HTML

  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Các thẻ HTML được chấp nhận: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Tự động ngắt dòng và đoạn văn.

Plain text

  • No HTML tags allowed.
  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Tự động ngắt dòng và đoạn văn.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Những điểm sáng tối trong lịch sử của Apple

Những điểm sáng tối trong lịch sử của Apple

Apple dưới sự chèo lái của “thầy phủ thủy” Steve Jobs luôn nổi tiếng với rất nhiều sản phẩm thành công...

Sản phẩm dịch vụ công trực tuyến liên thông tiết kiệm thời gian

Sản phẩm dịch vụ công trực tuyến liên thông tiết kiệm thời gian

Dịch vụ công trực tuyến là hệ thống giao dịch điện tử các thủ tục hành chính giữa Cơ quan Nhà nước với Công dân và Doanh nghiệp được phát triển bởi IT Software với mục tiêu

Bố già AI - chuyên gia AI người Việt Nguyễn Xuân Phong tại Tech Awards 2020

Bố già AI - chuyên gia AI người Việt Nguyễn Xuân Phong tại Tech Awards 2020

Với những người làm nghiên cứu, tư duy AI phải bắt đầu từ toán học như mạng neuron, thuật toán... Từ nền tảng cơ bản, chúng ta có thể tạo ra vô số ứng dụng

Công ty diệt chuột T&C

 

Diet con trung