Below is a PHP script that generates a password for .htpasswd from the clear text password stored in $clearTextPassword.
Please note: For Apache servers running on Windows you have to use the htpasswd program to generate passwords, or use the htpasswd generator.
1 2 3 4 5 6 7 8 9 10 |
<?php // Password to be encrypted for a .htpasswd file $clearTextPassword = 'some password'; // Encrypt password $password = crypt($clearTextPassword, base64_encode($clearTextPassword)); // Print encrypted password echo $password; ?> |
How to use the code:
- Copy the above the code and paste it into your favorite text editor (ie notepad).
- Change “some password” to the password you want to encrypt.
- Save the code in file called htpasswd.php.
- Upload htpasswd.php to your webserver.
- Execute the code by going to http://www.your-domain.com/htpasswd.php
- The outputted text is your encrypted password.