{"id":30,"date":"2020-02-12T10:36:13","date_gmt":"2020-02-12T10:36:13","guid":{"rendered":"https:\/\/www.lcn.com\/support\/knowledge-base\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/"},"modified":"2021-10-11T16:09:54","modified_gmt":"2021-10-11T16:09:54","slug":"how-to-password-protect-a-folder-on-your-website-with-htaccess","status":"publish","type":"ht_kb","link":"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/","title":{"rendered":"How to password protect a website folder using .htaccess"},"content":{"rendered":"\n<p>To add password protection to your website you need to create a file to store usernames\/passwords and add some code into a .htaccess file. This guide will show customers using LCN <a href=\"https:\/\/www.lcn.com\/web-hosting\" target=\"_blank\" rel=\"noopener noreferrer\">web hosting<\/a> and <a href=\"https:\/\/www.lcn.com\/web-hosting\/wordpress\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress hosting<\/a> how to get password protection working in no time.<\/p>\n<p>Let\u2019s get started\u2026<\/p>\n<h3>Creating the password file<\/h3>\n<p>The password file is a simple text file that contains a username and password separated by a colon (:). However, for security purposes the password must be encrypted. There\u2019re lots of free tools that will encrypt the password for you, but you can use our tool below. Simply enter the username and password you want to use and we&#8217;ll generate a string of text that you can copy and paste.<\/p>\n\n\n\n<script src=\"..\/..\/wp-content\/themes\/lcn-support\/assets\/js\/crypto\/core-min.js\"><\/script>\r\n<script src=\"..\/..\/wp-content\/themes\/lcn-support\/assets\/js\/crypto\/sha1.js\"><\/script>\r\n<script src=\"..\/..\/wp-content\/themes\/lcn-support\/assets\/js\/crypto\/enc-base64-min.js\"><\/script>\r\n\r\n<script>\r\n  function algo_sha1(name, pass) {\r\n    var hash = CryptoJS.SHA1(pass);\r\n    return name + ':{SHA}' + hash.toString(CryptoJS.enc.Base64);\r\n  }\r\n\r\n  \/\/function algo_ssha1(name, pass) {\r\n  \/\/  var salt = CryptoJS.lib.WordArray.random(32\/8);\r\n \/\/   var sha1 = CryptoJS.algo.SHA1.create();\r\n \/\/   sha1.update(pass);\r\n\/\/    sha1.update(salt);\r\n \/\/   var hash = sha1.finalize();\r\n\/\/    return name + ':{SSHA}' + hash.concat(salt).toString(CryptoJS.enc.Base64);\r\n\/\/  }\r\n  $(function() {\r\n    \/\/ Our supported algorithms\r\n    var ALGORITHMS = {\r\n      'sha1':   ['SHA1 sum in base64', algo_sha1],\r\n      \/\/'ssha1':  ['SHA1 salted sum in base64', algo_ssha1]\r\n   };\r\n    var algo_el = $('#algorithms');\r\n    for (var id in ALGORITHMS) {\r\n     algo_el.append('<option value=\"' + id +'\">' + ALGORITHMS[id][0] + '<\/option>');\r\n    }\r\n\r\n    $('#hash').click(function(event) {\r\n      event.preventDefault();\r\n      var algo = \"sha1\";\r\n      var name = $('#hthasher input[name=name]').val();\r\n      var pass = $('#hthasher input[name=pass]').val();\r\n      if (algo in ALGORITHMS) { \r\n        $('pre.result').html(ALGORITHMS[algo][1](name, pass))\r\n      }\r\n    });\r\n  });\r\n  <\/script> \n\n<div class=\"utility_form\">\n <form id=\"hthasher\">\n        <div class=\"span3\">\n           <input name=\"name\" type=\"text\" placeholder=\"Username\u2026\" class=\"span3\">\n           <input name=\"pass\" type=\"password\" placeholder=\"Password\u2026\" class=\"span3\">\n       <\/div>\n\t   <\/br>\n        <!--<div class=\"span2\">\n           <select class=\"span2\" id=\"algorithms\">\n           <\/select>\n        <\/div>-->\n        <div class=\"span6\">\n          <pre class=\"result\">&nbsp;<\/pre>\n\t\t  <\/br>\n          <button class=\"btn btn-large btn-primary\" id=\"hash\">Hash My Password!<\/button>\n        <\/div>\n        <\/form>\n<\/div>\n<br>\n\n\n\n<ol class=\"step_by_step\">\n<li>Create a file using a text editor such as Notepad or TextEdit.<\/li>\n<li>Save the file as: .htpasswd<\/li>\n<li>Copy and paste the username\/password string generated using our tool into the document.<\/li>\n<li>Upload the .htpasswd file to your website using FTP.<\/li>\n<\/ol>\n<\/br>\n\n<div class=\"container row col-md-24 support-article panel panel-default panel-body\" style=\"background-color: #f6e9db; border-color: #ead9c7; border: 1px solid #ddd; border-radius: 4px; padding: 1% 2%; background-image: url('\/images\/my_account\/highlight.png'); background-position: left top; background-repeat: repeat-x;\">\n<p><span style=\"font-size: 17px;\"><strong style=\"color: #e77600 !important; font-size: 18px;\">Please note:<\/strong> Instructions on uploading the file to your website can be found <a href=\"https:\/\/www.lcn.com\/support\/articles\/how-to-upload-files-to-your-website-with-ftp\/\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. <\/span><\/p>\n<\/div>\n\n<p>For extra security make sure that it is outside of your web folder so that it can never be accessed by someone going to http:\/\/www.domain.com\/.htpasswd. Our hosting servers will block web access to any files beginning with .ht, but it\u2019s recommended that the password file is not in a publicly accessible folder.<\/p>\n\n<h3>Creating the .htaccess file<\/h3>\n\n<p>Once you\u2019ve created and uploaded your .htpasswd file you&#8217;ll need to create a .htaccess file to tell the web server what folder you want to protect and what username\/password file to use.<\/p>\n\n<ol class=\"step_by_step\">\n<li>Create a file using a text editor such as Notepad or TextEdit.<\/li>\n<li>Save the file as: .htaccess (without any additional file extension).<\/li>\n<li>Enter the following lines of text within the file:<\/li>\n<\/ol>\n<\/br>\n\n<pre class=\"prettyprint linenums\">AuthType Basic <br>AuthName \"My Protected Folder\" <br>AuthUserFile ..\/..\/.htpasswd <br>require valid-user<\/pre>\n<\/br>\n<p>Let&#8217;s go through the parameters you&#8217;ve just set:<\/p>\n<\/br>\n\n<p><strong>Line 1:<\/strong><\/p>\n<pre class=\"prettyprint linenums\">AuthType Basic<\/pre>\n<\/br>\n<p>Defines the type of authentication the web server will use, \u2018Basic\u2019 is perfectly adequate for what we need.<\/p>\n\n<p><strong>Line 2:<\/strong><\/p>\n<pre class=\"prettyprint linenums\">AuthName \"My Protected Folder\"<\/pre>\n<\/br>\n<p>Sets the title of the username\/password box that will popup when someone tries to view your protected page.<\/p>\n\n<p><strong>Line 3:<\/strong><\/p>\n<pre class=\"prettyprint linenums\">AuthUserFile ..\/..\/.htpasswd<\/pre>\n<\/br>\n<p>Tells the web server where to find the username\/password file. You will need to update <i>..\/..\/.htpasswd<\/i> with a relative path to the location of your .htpasswd file.<\/p>\n<p>The <i>..\/..\/.htpasswd<\/i> path indicates the file is located two folders above the current directory, to point to a file within the same directory for example, you could use: <i>.\/.htpasswd<\/i><\/p>\n\n<p><strong>Line 4:<\/strong><\/p>\n<pre class=\"prettyprint linenums\">require valid-user<\/pre>\n<\/br>\n<p>Tells the web server who in your .htpasswd file can access your folder, by using valid-user everyone in the file can view the folder.<\/p>\n\n<h3>Where to upload your .htaccess file<\/h3>\n\n<p>The .htaccess file above will protect all the files in the folder it is uploaded into, and the sub-folders under it. For example, if you wanted to protect your entire website you could place the .htaccess file in your web folder.<\/p>\n\n<p><video autoplay=\"autoplay\" loop=\"loop\" muted=\"\" controls=\"controls\" width=\"100%\" height=\"100%\"><source src=\"\/support\/articles\/attachment\/558\/inline\/original\/1490688860\/htaccesspassword.mp4\">Your browser does not support the video tag.<\/video><\/p>\n\n<p>That\u2019s it! You\u2019ve successfully password protected your website.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To add password protection to your website you need to create a file to store usernames\/passwords and add some code into a .htaccess file. This guide will show customers using LCN web hosting and WordPress hosting how to get password protection working in no time. Let\u2019s get started\u2026 Creating the password file The password file [&hellip;]<\/p>\n","protected":false},"author":1,"comment_status":"closed","ping_status":"open","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[15],"ht-kb-tag":[5],"class_list":["post-30","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-creating-a-new-website","ht_kb_tag-web-hosting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to password protect a website folder using .htaccess - LCN.com<\/title>\n<meta name=\"description\" content=\"How to password protect folders at LCN.com.Follow this simple, step-by-step guide to password protect a folder on your website with .htaccess file.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to password protect a website folder using .htaccess - LCN.com\" \/>\n<meta property=\"og:description\" content=\"How to password protect folders at LCN.com.Follow this simple, step-by-step guide to password protect a folder on your website with .htaccess file.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/\" \/>\n<meta property=\"og:site_name\" content=\"Customer Support Guides - LCN\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/lcndotcom\" \/>\n<meta property=\"article:modified_time\" content=\"2021-10-11T16:09:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.lcn.com\/support\/wp-content\/uploads\/support-facebook-feed.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@lcndotcom\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/\",\"url\":\"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/\",\"name\":\"How to password protect a website folder using .htaccess - LCN.com\",\"isPartOf\":{\"@id\":\"https:\/\/www.lcn.com\/support\/#website\"},\"datePublished\":\"2020-02-12T10:36:13+00:00\",\"dateModified\":\"2021-10-11T16:09:54+00:00\",\"description\":\"How to password protect folders at LCN.com.Follow this simple, step-by-step guide to password protect a folder on your website with .htaccess file.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.lcn.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to password protect a website folder using .htaccess\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.lcn.com\/support\/#website\",\"url\":\"https:\/\/www.lcn.com\/support\/\",\"name\":\"Customer Support Guides - LCN\",\"description\":\"- LCN\",\"publisher\":{\"@id\":\"https:\/\/www.lcn.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.lcn.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.lcn.com\/support\/#organization\",\"name\":\"LCN.com\",\"url\":\"https:\/\/www.lcn.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.lcn.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.lcn.com\/support\/wp-content\/uploads\/2020\/02\/ZF_-hcc3.jpg\",\"contentUrl\":\"https:\/\/www.lcn.com\/support\/wp-content\/uploads\/2020\/02\/ZF_-hcc3.jpg\",\"width\":461,\"height\":461,\"caption\":\"LCN.com\"},\"image\":{\"@id\":\"https:\/\/www.lcn.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/lcndotcom\",\"https:\/\/x.com\/lcndotcom\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to password protect a website folder using .htaccess - LCN.com","description":"How to password protect folders at LCN.com.Follow this simple, step-by-step guide to password protect a folder on your website with .htaccess file.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/","og_locale":"en_US","og_type":"article","og_title":"How to password protect a website folder using .htaccess - LCN.com","og_description":"How to password protect folders at LCN.com.Follow this simple, step-by-step guide to password protect a folder on your website with .htaccess file.","og_url":"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/","og_site_name":"Customer Support Guides - LCN","article_publisher":"https:\/\/www.facebook.com\/lcndotcom","article_modified_time":"2021-10-11T16:09:54+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.lcn.com\/support\/wp-content\/uploads\/support-facebook-feed.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_site":"@lcndotcom","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/","url":"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/","name":"How to password protect a website folder using .htaccess - LCN.com","isPartOf":{"@id":"https:\/\/www.lcn.com\/support\/#website"},"datePublished":"2020-02-12T10:36:13+00:00","dateModified":"2021-10-11T16:09:54+00:00","description":"How to password protect folders at LCN.com.Follow this simple, step-by-step guide to password protect a folder on your website with .htaccess file.","breadcrumb":{"@id":"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.lcn.com\/support\/articles\/how-to-password-protect-a-folder-on-your-website-with-htaccess\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.lcn.com\/support\/"},{"@type":"ListItem","position":2,"name":"How to password protect a website folder using .htaccess"}]},{"@type":"WebSite","@id":"https:\/\/www.lcn.com\/support\/#website","url":"https:\/\/www.lcn.com\/support\/","name":"Customer Support Guides - LCN","description":"- LCN","publisher":{"@id":"https:\/\/www.lcn.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.lcn.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.lcn.com\/support\/#organization","name":"LCN.com","url":"https:\/\/www.lcn.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lcn.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.lcn.com\/support\/wp-content\/uploads\/2020\/02\/ZF_-hcc3.jpg","contentUrl":"https:\/\/www.lcn.com\/support\/wp-content\/uploads\/2020\/02\/ZF_-hcc3.jpg","width":461,"height":461,"caption":"LCN.com"},"image":{"@id":"https:\/\/www.lcn.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/lcndotcom","https:\/\/x.com\/lcndotcom"]}]}},"_links":{"self":[{"href":"https:\/\/www.lcn.com\/support\/wp-json\/wp\/v2\/ht-kb\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lcn.com\/support\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.lcn.com\/support\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.lcn.com\/support\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lcn.com\/support\/wp-json\/wp\/v2\/comments?post=30"}],"version-history":[{"count":28,"href":"https:\/\/www.lcn.com\/support\/wp-json\/wp\/v2\/ht-kb\/30\/revisions"}],"predecessor-version":[{"id":609,"href":"https:\/\/www.lcn.com\/support\/wp-json\/wp\/v2\/ht-kb\/30\/revisions\/609"}],"wp:attachment":[{"href":"https:\/\/www.lcn.com\/support\/wp-json\/wp\/v2\/media?parent=30"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.lcn.com\/support\/wp-json\/wp\/v2\/ht-kb-category?post=30"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.lcn.com\/support\/wp-json\/wp\/v2\/ht-kb-tag?post=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}