Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- foo:$apr1$y1cXxW5l$3vapv2yyCXaYz8zGoXj241
- foo:{SHA}BW6v589SIg3i3zaEW47RcMZ+I+M=
- <?php
- $login = 'foo';
- $pass = 'pass';
- $hash = base64_encode(sha1($pass, true));
- $contents = $login . ':{SHA1}' . $hash;
- file_set_contents('.htpasswd', $contents);
- ?>
- <FORM METHOD="POST" ACTION="<? echo $_SERVER['PHP_SELF']; ?>" onSubmit='return ValidateForm()'>
- Username<br /><INPUT TYPE="TEXT" NAME="user[]"><br /><br />
- Password<br /><INPUT TYPE="PASSWORD" NAME="password1[]"><br />
- <INPUT TYPE="PASSWORD" NAME="password2[]"><br /><br />
- <INPUT type=submit name="submit" VALUE="Create .htpasswd entry" onclick="document.all.submit.style.visibility='hidden'">
- </FORM>
- if ( isset($_POST['user']) && isset($_POST['password1'])) {
- if( $_POST['password1'] == $_POST['password2'] ) {
- $user = $_POST['user'];
- $password1 = $_POST['password1'];
- $htpasswd_text = "";
- for ($i = 0; $i < count ($user); $i++) {
- $htpasswd_text .= "$user[$i]:".crypt($password1[$i],CRYPT_STD_DES)."";
- }
- echo "<br />Copy this line to your .htpasswd file:";
- echo "<pre style="border-bottom-width:1px;border-bottom-style:solid;">";
- echo nl2br($htpasswd_text);
- echo "</pre><br />";
- } else {
- echo "<pre style="border-bottom-width:1px;border-bottom-style:solid;">Passwords do not match !</pre><br />";
- }
- }
- <?php
- // Set the password & username
- $username = 'user';
- $password = 'mypassword';
- // Get the hash, letting the salt be automatically generated
- $hash = crypt($password);
- // write to a file
- file_set_contents('.htpasswd', $username ':' . $contents);
- ?>
Add Comment
Please, Sign In to add comment