create htaccess password generator using php

create htaccess password generator using php

create htaccess password generator using php

In this tutorial let us check how to create htaccess password generator using php script. By using htaccess password we can protect a directory/ folder from unauthorized access.
Do you want to protect a specific folder from unauthorized access, or do you want to protect your development server website from accessing someone else? Then you can do this by using htpasswd file.

The htpasswd file is having the authorization information of accessing a directory/folder in your website. In htpasswd you can store username and password for accessing a website. You also need to tell which is the htpasswd file in htaccess. If you want to know about how to create htaccess ipaddress banning generator, Check this tutorial.

Let us check how can we create htaccess password generator using php script. By using this script you can easily create details that need to enter in the htpasswd file and htaccess file.

let us move into coding. Here we are going to write a simple php code which will have one simple html form for inpting the username, password, the htpasswd location etc. After submitting the form the script will process the information given by the user and will generate htpasswd and htaccess information.

<?php

if($_POST['submit']){

	$uname=$_POST['username'];
	$htaccess_text_password=$_POST['password'];
	$htaccess_location=$_POST['location'];
    $password = crypt($htaccess_text_password, base64_encode($htaccess_text_password));
	$htpasswd_info=$uname.":".$password;

	$htaccess_code= "AuthUserFile $htaccess_location
					AuthName 'admin Login Area'
					AuthType Basic
					require user admin";

}

?>

<form action="" method="post" >
user name: <input type="text" name="username"></br></br>
password: <input type="text" name="password"></br></br>
htpasswd file location</br>(location where you like to put the htpasswd file </br>ex:/home/site/public_html/admin/.htpasswd): <input type="text" name="location"></br></br>
<input type="submit" name="submit" value="submit"></br></br>
</form>

<?php if($_POST['submit']){ ?>

put this code in .htpasswd file <textarea style="height:169px;width: 348px;"><?php echo $htpasswd_info; ?> </textarea></br></br>
put this code in .htaccess file <textarea style="height:169px;width: 348px;"><?php echo $htaccess_code; ?> </textarea></br>
<?php } ?>

so from the above php code you can create create htaccess password generator easily.
So after geting the password and username information that got to htpasswd file. Also paste the htpasswd file location information to the htaccess file.

Download              Demo