{"id":1673,"date":"2014-03-02T21:01:40","date_gmt":"2014-03-03T05:01:40","guid":{"rendered":"http:\/\/www.virendrachandak.com\/techtalk\/\/?p=1673"},"modified":"2025-12-17T15:48:11","modified_gmt":"2025-12-17T23:48:11","slug":"using-php-create-passwords-for-htpasswd-file","status":"publish","type":"post","link":"https:\/\/www.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/","title":{"rendered":"How to generate passwords for .htpasswd using PHP"},"content":{"rendered":"<p>In my earlier post about .htaccess I had described about <a href=\"https:\/\/www.virendrachandak.com\/techtalk\/htaccess-tips\/#htaccess_authentication\" title=\"Authentication using .htaccess file\">authentication using .htaccess<\/a> and command to generate .htpasswd file. However, when we want to add passwords for many users that method will take too long, since we will have to add passwords for each user one at a time. However, there is an easier way to generate the .htpasswd file using PHP. In this post I will show the different algorithms which can be used to generate the .htpasswd file.<br \/>\n<!--more--><\/p>\n<h3>Method 1: Using crypt() function.<\/h3>\n<p>This uses method uses crypt() encryption for passwords. This used to be the default algorithm used by Apache (2.2.17 and older). The password generated by this method will not work on Windows systems as they use MD5 based passwords. This method is same as using the command :<\/p>\n<pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">htpasswd -d \/usr\/local\/etc\/apache\/.htpasswd user1<\/pre>\n<p>The output of the code below can be directly added to the .htpasswd file.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n\/\/ Password to be used for the user\r\n$username = &#039;user1&#039;;\r\n$password = &#039;password1&#039;;\r\n\r\n\/\/ Encrypt password\r\n$encrypted_password = crypt($password, base64_encode($password));\r\n\r\n\/\/ Print line to be added to .htpasswd file\r\necho $username . &#039;:&#039; . $encrypted_password;\r\n<\/pre>\n<div>Sample Output:<\/div>\n<pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">user1:MzKS62M\/K9HSs<\/pre>\n<h3>Method 2: Using APR1-MD5 algorithm<\/h3>\n<p>MD5 encryption method is more secure than the crypt method. This is the default method since Apache 2.2.18. The password generated by using this method can be used on both Windows and Linux based systems. This method is same as using the command :<\/p>\n<pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">htpasswd -m \/usr\/local\/etc\/apache\/.htpasswd user1<\/pre>\n<p>Here is a script which I created based on the function I found on <a href=\"http:\/\/stackoverflow.com\/a\/8786956\/387247\" rel=\"external nofollow noopener noreferrer\" target=\"_blank\">Stack Overflow<\/a>.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n\/\/ APR1-MD5 encryption method (windows compatible)\r\nfunction crypt_apr1_md5($plainpasswd)\r\n{\r\n$salt = substr(str_shuffle(&quot;abcdefghijklmnopqrstuvwxyz0123456789&quot;), 0, 8);\r\n$len = strlen($plainpasswd);\r\n$text = $plainpasswd.&#039;$apr1$&#039;.$salt;\r\n$bin = pack(&quot;H32&quot;, md5($plainpasswd.$salt.$plainpasswd));\r\nfor($i = $len; $i &gt; 0; $i -= 16) { $text .= substr($bin, 0, min(16, $i)); }\r\n\/\/ for PHP version &lt; 8\r\n\/\/ for($i = $len; $i &gt; 0; $i &gt;&gt;= 1) { $text .= ($i &amp; 1) ? chr(0) : $plainpasswd{0}; }\r\n\/\/ for PHP 8+\r\nfor($i = $len; $i &gt; 0; $i &gt;&gt;= 1) { $text .= ($i &amp; 1) ? chr(0) : $plainpasswd&#x5B;0]; }\r\n$bin = pack(&quot;H32&quot;, md5($text));\r\nfor($i = 0; $i &lt; 1000; $i++)\r\n{\r\n$new = ($i &amp; 1) ? $plainpasswd : $bin;\r\nif ($i % 3) $new .= $salt;\r\nif ($i % 7) $new .= $plainpasswd;\r\n$new .= ($i &amp; 1) ? $bin : $plainpasswd;\r\n$bin = pack(&quot;H32&quot;, md5($new));\r\n}\r\nfor ($i = 0; $i &lt; 5; $i++)\r\n{\r\n$k = $i + 6;\r\n$j = $i + 12;\r\nif ($j == 16) $j = 5;\r\n$tmp = $bin&#x5B;$i].$bin&#x5B;$k].$bin&#x5B;$j].$tmp;\r\n}\r\n$tmp = chr(0).chr(0).$bin&#x5B;11].$tmp;\r\n$tmp = strtr(strrev(substr(base64_encode($tmp), 2)),\r\n&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/&quot;,\r\n&quot;.\/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;);\r\n\r\nreturn &quot;$&quot;.&quot;apr1&quot;.&quot;$&quot;.$salt.&quot;$&quot;.$tmp;\r\n}\r\n\r\n\/\/ Password to be used for the user\r\n$username = &#039;user1&#039;;\r\n$password = &#039;password1&#039;;\r\n\r\n\/\/ Encrypt password\r\n$encrypted_password = crypt_apr1_md5($password);\r\n\r\n\/\/ Print line to be added to .htpasswd file\r\necho $username . &#039;:&#039; . $encrypted_password;\r\n<\/pre>\n<div>Sample Output:<\/div>\n<pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">user1:$apr1$e5cytbnu$ps.bh8zF0tkJpEgkGtYcf0<\/pre>\n<div>We can use either of the above methods, however, the preferred method is to use the MD5 algorithm, since it is more secure and also works on both Windows and Linux systems.<\/div>\n<div>Using any of the above methods and a loop we can easily generate the passwords for many users. We can use loop similar to the following to generate the passwords to be added to the .htpasswd file.<\/p>\n<div>\n<div>\n<div>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/\/ Array for usernames and password.\r\n$users = array();\r\n\/\/ User 1\r\n$users&#x5B;0]&#x5B;&#039;username&#039;] = &#039;user1&#039;;\r\n$users&#x5B;0]&#x5B;&#039;password&#039;] = &#039;password1&#039;;\r\n\/\/ User 2\r\n$users&#x5B;1]&#x5B;&#039;username&#039;] = &#039;user2&#039;;\r\n$users&#x5B;1]&#x5B;&#039;password&#039;] = &#039;password2&#039;;\r\n\/\/ User 3\r\n$users&#x5B;2]&#x5B;&#039;username&#039;] = &#039;user3&#039;;\r\n$users&#x5B;2]&#x5B;&#039;password&#039;] = &#039;password3&#039;;\r\n\r\nforeach($users as $user =&gt; $data)\r\n{\r\n$username = $data&#x5B;&#039;username&#039;];\r\n$password = $data&#x5B;&#039;password&#039;];\r\n\/\/ Encrypt password\r\n$encryptedpwd = crypt_apr1_md5($password);\r\n\r\n\/\/ Print line to be added to .htpasswd file\r\n$content = $username . &#039;:&#039; . $encryptedpwd;\r\necho $content . &#039;&lt;br \/&gt;&#039;;\r\n}\r\n<\/pre>\n<div>Sample Output:<\/div>\n<pre class=\"brush: plain; gutter: false; title: ; notranslate\" title=\"\">user1:$apr1$9qrj2x80$p2L32fS0tO7JgwzUISW8b.\r\nuser2:$apr1$hmay01vn$uIHCNVBgF5qH5jmNBIzw4\/\r\nuser3:$apr1$v2tohm9c$3TtZAPuaD4dhPF62kPOwO\/<\/pre>\n<p>By using PHP we can easily generate the code to be added to .htpasswd file for many users very easily. All the usernames and passwords in my examples are just sample users. Make use the username that you want and a different, more secure, password.<\/p>\n<\/div>\n<div><a id=\"demo_link\" data-title=\"View Demo\" href=\"https:\/\/www.virendrachandak.com\/demos\/using-php-create-passwords-for-htpasswd-file.php\"> View Demo<\/a><\/div>\n<div><a id=\"demo_link\" data-title=\"View Demo\" href=\"https:\/\/www.virendrachandak.com\/demos\/using-php-create-passwords-for-htpasswd-file.php\"><\/a><\/div>\n<\/div>\n<p><strong>Update<\/strong>: Newer versions of Apache can use BCRPYT for password hash so here is another posts about <a href=\"https:\/\/www.virendrachandak.com\/techtalk\/using-php-bcrypt-algorithm-for-htpasswd-generation\/\" target=\"_blank\" rel=\"noopener noreferrer\">Generating bcrypt .htpasswd passwords using PHP<\/a>.<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In my earlier post about .htaccess I had described about authentication using .htaccess and command to generate .htpasswd file. However, when we want to add passwords for many users that method will take too long, since we will have to add passwords for each user one at a time. However, there is an easier way [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"How to generate password for .htpasswd using PHP","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[131,6,8],"tags":[15,16,20,28],"class_list":["post-1673","post","type-post","status-publish","format-standard","hentry","category-security","category-server-configuration","category-web-development","tag-htaccess","tag-htpasswd","tag-apache","tag-configuration-file"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to generate passwords for .htpasswd using PHP - Virendra&#039;s TechTalk<\/title>\n<meta name=\"description\" content=\"This post describes different methods to generate .htpasswd file using crypt and MD5 methods. The MD5 method can be used for both Linux and WIndows systems.\" \/>\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.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to generate passwords for .htpasswd using PHP - Virendra&#039;s TechTalk\" \/>\n<meta property=\"og:description\" content=\"This post describes different methods to generate .htpasswd file using crypt and MD5 methods. The MD5 method can be used for both Linux and WIndows systems.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/\" \/>\n<meta property=\"og:site_name\" content=\"Virendra&#039;s TechTalk\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/virendrachandak\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/virendrachandak\" \/>\n<meta property=\"article:published_time\" content=\"2014-03-03T05:01:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-17T23:48:11+00:00\" \/>\n<meta name=\"author\" content=\"Virendra Chandak\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@virendrachandak\" \/>\n<meta name=\"twitter:site\" content=\"@virendrachandak\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virendra Chandak\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/using-php-create-passwords-for-htpasswd-file\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/using-php-create-passwords-for-htpasswd-file\\\/\"},\"author\":{\"name\":\"Virendra Chandak\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/63f7ffa1ea125e32af9618d188349e17\"},\"headline\":\"How to generate passwords for .htpasswd using PHP\",\"datePublished\":\"2014-03-03T05:01:40+00:00\",\"dateModified\":\"2025-12-17T23:48:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/using-php-create-passwords-for-htpasswd-file\\\/\"},\"wordCount\":740,\"commentCount\":8,\"publisher\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/63f7ffa1ea125e32af9618d188349e17\"},\"keywords\":[\".htaccess\",\".htpasswd\",\"Apache\",\"Configuration file\"],\"articleSection\":[\"Security\",\"Server Configuration\",\"Web Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/using-php-create-passwords-for-htpasswd-file\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/using-php-create-passwords-for-htpasswd-file\\\/\",\"url\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/using-php-create-passwords-for-htpasswd-file\\\/\",\"name\":\"How to generate passwords for .htpasswd using PHP - Virendra&#039;s TechTalk\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#website\"},\"datePublished\":\"2014-03-03T05:01:40+00:00\",\"dateModified\":\"2025-12-17T23:48:11+00:00\",\"description\":\"This post describes different methods to generate .htpasswd file using crypt and MD5 methods. The MD5 method can be used for both Linux and WIndows systems.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/using-php-create-passwords-for-htpasswd-file\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/using-php-create-passwords-for-htpasswd-file\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/using-php-create-passwords-for-htpasswd-file\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"TechTalk\",\"item\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Security\",\"item\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/category\\\/security\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to generate passwords for .htpasswd using PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#website\",\"url\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/\",\"name\":\"Virendra's TechTalk\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/63f7ffa1ea125e32af9618d188349e17\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/63f7ffa1ea125e32af9618d188349e17\",\"name\":\"Virendra Chandak\",\"logo\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.virendrachandak.com\",\"https:\\\/\\\/www.facebook.com\\\/virendrachandak\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/virendrachandak\\\/\",\"https:\\\/\\\/x.com\\\/virendrachandak\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to generate passwords for .htpasswd using PHP - Virendra&#039;s TechTalk","description":"This post describes different methods to generate .htpasswd file using crypt and MD5 methods. The MD5 method can be used for both Linux and WIndows systems.","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.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/","og_locale":"en_US","og_type":"article","og_title":"How to generate passwords for .htpasswd using PHP - Virendra&#039;s TechTalk","og_description":"This post describes different methods to generate .htpasswd file using crypt and MD5 methods. The MD5 method can be used for both Linux and WIndows systems.","og_url":"https:\/\/www.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/","og_site_name":"Virendra&#039;s TechTalk","article_publisher":"https:\/\/www.facebook.com\/virendrachandak","article_author":"https:\/\/www.facebook.com\/virendrachandak","article_published_time":"2014-03-03T05:01:40+00:00","article_modified_time":"2025-12-17T23:48:11+00:00","author":"Virendra Chandak","twitter_card":"summary_large_image","twitter_creator":"@virendrachandak","twitter_site":"@virendrachandak","twitter_misc":{"Written by":"Virendra Chandak","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/#article","isPartOf":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/"},"author":{"name":"Virendra Chandak","@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17"},"headline":"How to generate passwords for .htpasswd using PHP","datePublished":"2014-03-03T05:01:40+00:00","dateModified":"2025-12-17T23:48:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/"},"wordCount":740,"commentCount":8,"publisher":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17"},"keywords":[".htaccess",".htpasswd","Apache","Configuration file"],"articleSection":["Security","Server Configuration","Web Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/","url":"https:\/\/www.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/","name":"How to generate passwords for .htpasswd using PHP - Virendra&#039;s TechTalk","isPartOf":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#website"},"datePublished":"2014-03-03T05:01:40+00:00","dateModified":"2025-12-17T23:48:11+00:00","description":"This post describes different methods to generate .htpasswd file using crypt and MD5 methods. The MD5 method can be used for both Linux and WIndows systems.","breadcrumb":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.virendrachandak.com\/techtalk\/using-php-create-passwords-for-htpasswd-file\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"TechTalk","item":"https:\/\/www.virendrachandak.com\/techtalk\/"},{"@type":"ListItem","position":2,"name":"Security","item":"https:\/\/www.virendrachandak.com\/techtalk\/category\/security\/"},{"@type":"ListItem","position":3,"name":"How to generate passwords for .htpasswd using PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.virendrachandak.com\/techtalk\/#website","url":"https:\/\/www.virendrachandak.com\/techtalk\/","name":"Virendra's TechTalk","description":"","publisher":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.virendrachandak.com\/techtalk\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17","name":"Virendra Chandak","logo":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/www.virendrachandak.com","https:\/\/www.facebook.com\/virendrachandak","https:\/\/www.linkedin.com\/in\/virendrachandak\/","https:\/\/x.com\/virendrachandak"]}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2vTtQ-qZ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/posts\/1673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/comments?post=1673"}],"version-history":[{"count":4,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/posts\/1673\/revisions"}],"predecessor-version":[{"id":2611,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/posts\/1673\/revisions\/2611"}],"wp:attachment":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/media?parent=1673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/categories?post=1673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/tags?post=1673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}