{"id":229,"date":"2016-05-04T10:13:56","date_gmt":"2016-05-04T08:13:56","guid":{"rendered":"https:\/\/wpethzprd.ethz.ch\/isgdmath\/?p=229"},"modified":"2023-05-17T10:40:06","modified_gmt":"2023-05-17T08:40:06","slug":"webpage-with-password","status":"publish","type":"post","link":"https:\/\/blogs.ethz.ch\/isgdmath\/webpage-with-password\/","title":{"rendered":"How to Protect a Webpage with a Password"},"content":{"rendered":"<p class=\"p\">Suppose you want to protect the sub-page &#8220;secure&#8221; of your homepage with a password; that is you want that the visitors are asked for a username and a password when accessing a webpage:<!--more--><\/p>\n<ul class=\"nobullet\">\n<li>https:\/\/people.math.ethz.ch\/~USERNAME\/secure\/<\/li>\n<\/ul>\n<p class=\"p\">To do that you first have to create the directory &#8220;secure&#8221; with the correct permissions:<\/p>\n<pre class=\"pre\">mkdir ~\/www\/secure\nchmod 755 ~\/www\/secure\n<\/pre>\n<p class=\"p\">Then you have to create a kind of configuration file in that directory, named <em>.htaccess<\/em> with the following content (you can use emacs, xemacs, vi, &#8230; as editor)<\/p>\n<pre class=\"pre\">AuthName \"This is my protected page...\"\nAuthType Basic\nAuthUserFile \/hg\/w\/www1\/users\/USERNAME\/www\/.htpasswd\nrequire valid-user<\/pre>\n<p class=\"p\">and change the permissions as follows:<\/p>\n<pre class=\"pre\">chmod 644 ~\/www\/secure\/.htaccess\n<\/pre>\n<p class=\"p\">As last step, you have to create a list of user(s) with password(s) (see the directive <em>AuthUserFile<\/em> above). To do that just enter the following command:<\/p>\n<pre class=\"pre\">htpasswd -c ~\/www\/.htpasswd user1\nNew password: ******\nRe-type new password: ******\nAdding password for user user1<\/pre>\n<p class=\"p\">The option &#8220;-c&#8221; has to be used only the first time, since it will create the file <em>.htpasswd<\/em>. If you want to add more users, use the same command without the &#8220;-c&#8221;:<\/p>\n<pre class=\"pre\">htpasswd ~\/www\/.htpasswd user2\nNew password: ******\nRe-type new password: ******\nAdding password for user user2\n<\/pre>\n<p class=\"p\">and check the permissions again:<\/p>\n<pre class=\"pre\">chmod 644 ~\/www\/.htpasswd\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Suppose you want to protect the sub-page &#8220;secure&#8221; of your homepage with a password; that is you want that the visitors are asked for a username and a password when accessing a webpage:<\/p>\n","protected":false},"author":43853,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1365,891],"tags":[],"class_list":["post-229","post","type-post","status-publish","format-standard","hentry","category-password","category-web"],"_links":{"self":[{"href":"https:\/\/blogs.ethz.ch\/isgdmath\/wp-json\/wp\/v2\/posts\/229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ethz.ch\/isgdmath\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ethz.ch\/isgdmath\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ethz.ch\/isgdmath\/wp-json\/wp\/v2\/users\/43853"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ethz.ch\/isgdmath\/wp-json\/wp\/v2\/comments?post=229"}],"version-history":[{"count":0,"href":"https:\/\/blogs.ethz.ch\/isgdmath\/wp-json\/wp\/v2\/posts\/229\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.ethz.ch\/isgdmath\/wp-json\/wp\/v2\/media?parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ethz.ch\/isgdmath\/wp-json\/wp\/v2\/categories?post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ethz.ch\/isgdmath\/wp-json\/wp\/v2\/tags?post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}