Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

วิธีการป้องกันรหัสผ่านหน้าเข้าสู่ระบบด้วยการตรวจสอบสิทธิ์ HTTP

หน้าเข้าสู่ระบบป้องกันรหัสผ่านด้วยการตรวจสอบสิทธิ์ HTTP: มีเว็บไซต์ WordPress 60 ล้านเว็บไซต์ซึ่งทำให้เป็นแพลตฟอร์มการสร้างเว็บไซต์ที่ได้รับความนิยมมากที่สุดในโลก แต่มีราคาสำหรับความนิยมนี้ มีการพยายามแฮ็ค 90,978 ครั้งบนไซต์ WordPress ทุกนาทีของวัน แม้ว่าจะมีวิธีการต่างๆ ที่แฮ็กเกอร์ใช้เพื่อเจาะเข้าไปในเว็บไซต์ แต่วิธีหนึ่งที่ได้รับความนิยมและใช้กันอย่างแพร่หลายเรียกว่าการโจมตีด้วยกำลังเดรัจฉาน ในการโจมตีประเภทนี้ แฮกเกอร์จะตั้งโปรแกรมบอทให้ลองเดาข้อมูลการเข้าสู่ระบบของคุณอย่างถูกต้อง นั่นคือเหตุผลที่คุณต้องปกป้องหน้าเข้าสู่ระบบ WordPress ของคุณ

ในโพสต์ก่อนหน้านี้เกี่ยวกับการป้องกันการเข้าสู่ระบบ เราได้พูดคุยถึงการตั้งชื่อผู้ใช้ที่ไม่ซ้ำกันและการบังคับใช้รหัสผ่านที่รัดกุม เป็นวิธีที่มีประสิทธิภาพในการป้องกันไม่ให้บอทของแฮ็กเกอร์ออกจากไซต์ของคุณ แต่เมื่อพูดถึงเรื่องความปลอดภัย ไม่มีการรับประกันใด ๆ ว่าไซต์จะปลอดภัย อินเทอร์เน็ตไม่เคยเป็นสถานที่ที่ปลอดภัยมาก่อน และการรักษาความปลอดภัยไม่เคยเพียงพอ ดังนั้นจึงเป็นการดีที่จะมีการป้องกันหลายชั้นสำหรับไซต์ของคุณ แม้ว่าชื่อผู้ใช้และรหัสผ่านที่ไม่ซ้ำกันจะมีความสำคัญ แต่การล็อกหน้าเข้าสู่ระบบก็เป็นขั้นตอนสำคัญในการรักษาความปลอดภัยเช่นกัน วิธีหนึ่งในการทำคือใช้รหัสผ่านป้องกันหน้าเข้าสู่ระบบด้วยการตรวจสอบสิทธิ์ HTTP ในโพสต์นี้ เราจะแสดงให้คุณเห็นว่าคุณจะบรรลุเป้าหมายได้อย่างไร

การตรวจสอบสิทธิ์ HTTP คืออะไร

HTTP Authentication หรือ HTTP Basic Authentication (BA) เป็นเทคนิคในการบังคับใช้การเข้าถึงหน้าล็อกอินอย่างจำกัด หากต้องการเปรียบเทียบง่ายๆ ให้คิดว่าเว็บไซต์เป็นเหมือนบ้าน ประตูหลักคือหน้าเข้าสู่ระบบ ผู้คนอาจพยายามบุกเข้าไปในบ้าน คุณจึงต้องล็อกแน่นหนา ตัวล็อคหมายถึงข้อมูลการเข้าสู่ระบบ นอกประตูหลักมีรั้วที่ให้การปกป้องเป็นพิเศษกับบ้าน ในลักษณะที่คล้ายคลึงกัน HTTP Authentication ให้ชั้นการป้องกันพิเศษแก่บ้านของคุณ ซึ่งหมายความว่าใครก็ตามที่ต้องการเข้าถึงหน้าเข้าสู่ระบบจะต้องผ่านการตรวจสอบสิทธิ์ HTTP (รั้ว) และข้อมูลรับรองการเข้าสู่ระบบ (ประตูหลัก) ก่อน

วิธีการป้องกันรหัสผ่านหน้าเข้าสู่ระบบด้วยการตรวจสอบสิทธิ์ HTTP ?

ในการรักษาความปลอดภัยไซต์ WordPress ของคุณด้วยการรับรองความถูกต้อง HTTP สิ่งแรกที่คุณต้องทำคือสร้างไฟล์ .htpasswd จากนั้นคุณจะต้องแจ้งไฟล์ .htaccess ของเว็บไซต์ของคุณเกี่ยวกับตำแหน่งของไฟล์ .htpasswd และนั่นจะล็อคหน้าเข้าสู่ระบบของคุณ

จะสร้างไฟล์ .htpasswd ได้อย่างไร

ในไฟล์นี้ คุณจะเก็บชื่อผู้ใช้และรหัสผ่านของบุคคลที่คุณต้องการเข้าถึงในหน้าเข้าสู่ระบบ โดยพื้นฐานแล้วมันเหมือนกับการมีประตูรั้วที่ล้อมรอบบ้านของคุณ คุณสามารถมอบกุญแจประตูให้กับคนที่คุณต้องการให้เข้าถึงไซต์ของคุณได้เท่านั้น มาดูวิธีสร้างไฟล์ .htpasswd กันเถอะ

ในการสร้างไฟล์ .htpasswd ใหม่ คุณต้องใช้เครื่องมือบรรทัดคำสั่ง .htpasswd มีเครื่องมือหลายอย่างออนไลน์ เมื่อคุณพบสิ่งที่คุณต้องการใช้ ให้เปิดและในบรรทัดคำสั่ง ให้เขียนโค้ดต่อไปนี้:

htpasswd -c .htpasswd harini

ในบรรทัดคำสั่งนี้ c หมายถึง create และ harini คือชื่อผู้ใช้ที่เราเลือก หลังจากพิมพ์รหัสนี้แล้ว เมื่อคุณกด Enter คุณจะได้รับแจ้งให้สร้างรหัสผ่านที่ไม่ซ้ำกับชื่อผู้ใช้นี้ ไม่ต้องกังวล; รหัสผ่านของคุณจะถูกเข้ารหัส

วิธีการป้องกันรหัสผ่านหน้าเข้าสู่ระบบด้วยการตรวจสอบสิทธิ์ HTTP

แต่ถ้าคุณมีไฟล์ .htpasswd อยู่แล้ว สิ่งที่คุณต้องทำคือเพิ่มชื่อผู้ใช้และรหัสผ่านใหม่ คุณสามารถทำได้โดยเขียนบรรทัดคำสั่งต่อไปนี้:

htpasswd .htpasswd ราหุล

สังเกตว่าเราไม่ได้ใช้ -c ที่นี่เพราะเราไม่ได้สร้างไฟล์ใหม่

วิธีการป้องกันรหัสผ่านหน้าเข้าสู่ระบบด้วยการตรวจสอบสิทธิ์ HTTP

โดยทั่วไป ไฟล์ .htpasswd จะมีลักษณะดังนี้:username:encrypted_password So if the username is harini and the password is dummy123pass, then the .htaccess file would be:harini:$apr1$50r17zis$lNbFJs4rQFfkp4ToO2/ZS/

The password has been encrypted. This .htaccess file is essentially your HTTP Basic Authentication credentials.

In case, you don’t want to use a tool or don’t know how to; you can use a .htpasswd generator. Open this link, and you should be able to see a window like an image below.

วิธีการป้องกันรหัสผ่านหน้าเข้าสู่ระบบด้วยการตรวจสอบสิทธิ์ HTTP

Type the username and password of your choice. There is an option to generate a random password too. Once done, hit the button that says Generate .htpasswd file. You should be able to see an output.

Modifying the .htaccess File

The .htaccess file is one of the most important files of your WordPress site. There are two things we’ll do with your .htaccess file. One, we’ll tell it what it needs to restrict and two, we tell it from where it could get the HTTP Basic Authentication credentials we just created in the steps above.

.htaccess is present in the public_html folder. To access it you will have to visit your web host account. Log in to your web host and go to a page called cPanel. There you should be able to find an option for File Manager. Select that, and a page will open, and in that page, you should be able to view the file.

วิธีการป้องกันรหัสผ่านหน้าเข้าสู่ระบบด้วยการตรวจสอบสิทธิ์ HTTP

Sometimes .htaccess is hidden and may not appear in the public_html folder. When that’s the case, what you need to do is go back to the cPanel, and click on File Manager. A popup will appear where you’ll have to select ‘Show Hidden Files.’

วิธีการป้องกันรหัสผ่านหน้าเข้าสู่ระบบด้วยการตรวจสอบสิทธิ์ HTTP

Next, you need download the file and then open it to add this code of line:

<Files wp-login.php>

AuthUserFile /path/to/.htpasswd

AuthName "Private access"

AuthType Basic

require valid-user

</Files>

A few things you need to keep in mind when inserting this code: AuthUserFile /path/to/.htpasswd – is the path to the .htpasswd file you just created. Make sure the path is correct. The term ‘valid-user’ tells the system any user who has been mentioned in the .htpasswd file with access to the login page. But if you want to be selective about who you grant access to, then instead of using ‘valid-user’, you can just mention the usernames.

After you are done, save it and upload it to the same place from where you downloaded it. And that’s it. The next time you try to access the login page, you’ll see a small window appearing asking you for specific login credentials.

Besides HTTPS authentication, we suggest that you also implement two-factor authentication, which will add another layer of security to your WordPress login page.

Also take a few more security measures like moving your site from HTTP to HTTPS, installing a security plugin, protecting the login page, etc. While protecting your login page is a great idea, there are other ways in which hackers can gain access to your website. We strongly suggest that you take a more holistic approach to security by following our guide on Complete WordPress Security.