Cái này dùng để bảo vệ thư mục bằng mật khầu và username và mật khẩu do mình định, tài khoản mình định này muốn hack chắc là ko thể, trừ phi các cậu chmod hổng quá hay bị dính keylog mà thôi. Ngoài ra nó còn dc dùng để antiDDOS Để bảo vệ khu vực admin, chúng ta sẽ tạo 1 file .htaccess với nội dung sau: Mã: AuthName "Ban phai nhap username va pass de tiep tuc" AuthType Basic AuthUserFile /d/home/www.mysite.com/htdocs/files/.htpasswd require valid-user Sauđó upload nó vào thư mục admin. Hãy chú ý đến dòng ghi đường dẫn đến file .htpasswd Nó được ghi từ thư mục gốc của server. File .htpasswd có thể để ở bất kỳ vị trí nào trên host của bạn, nhưng tốt nhất để ngoài thư mục gốc của site. Bước tiếp theo, chúng ta sẽ tạo file .htpasswd – nơi lưu giữ login và password để đăng nhập vào khu vực admin. Nó có dạng Mã: username:matkhaudadcmahoa Mật khẩu sẽ dc mã hóa
Bổ sung: Lệnh tạo file chứa user và pasword cho htaccess Yêu cầu: Máy đã cài đặt apache (windows hay linux gì cũng được). Vd ở đây SUN dùng Windows7, đã cài apache. Thử tạo file .text để lưu username là admin và mật khẩu là 123456, lưu vào ổ C:\. Vào CMD gõ Mã: C:\Users\Administrator>htpasswd -bc c:/.text admin 123456 Automatically using MD5 format. Adding password for user admin File chứa username và mật khẩu có nội dung (mật khẩu đã được băm ) Mã: admin:$apr1$be1.....$hqJ2vdt0eiiFNnNmWt1oN1 Giải thích: Mã: Usage: htpasswd [-cmdpsD] passwordfile username htpasswd -b[cmdpsD] passwordfile username password htpasswd -n[mdps] username htpasswd -nb[mdps] username password -c Create a new file. -n Don't update file; display results on stdout. -m Force MD5 encryption of the password (default). -d Force CRYPT encryption of the password. -p Do not encrypt the password (plaintext). -s Force SHA encryption of the password. -b Use the password from the command line rather than prompting for it. -D Delete the specified user. On Windows, NetWare and TPF systems the '-m' flag is used by default. On all other systems, the '-p' flag will probably not work.