|
|
|
|
|
|
| |
| <?php
// The following class encrypts a password, and writes it to a .htpasswd
// file for use with .htaccess encryption.
// Example usage:
//
// $username="bob";
// $password = "bob";
// $theLine = $htpasswd->genLine($username, $password);
// $htpasswd->writeFile(".htpasswd",$theLine);
//
//
//
// NOTE: Do NOT encrypt the password before calling the genLine function,
// otherwise the password will be encrypted twice, and will not work.
//
// Any questions, IM me www NLH com on AIM. Enjoy! =)
// START CODE
class htpasswd {
// Encrypts given password
function encryptPW($thePW){
$thePW = crypt(trim($thePW),base64_encode(CRYPT_STD_DES));
return $thePW;
}
// Calls the encryptPW function, generates the line for writing
function genLine($username,$password){
$encrypted_password = encryptPW($password);
return "$username:$encrypted_password";
}
// Writes data to the file
function writeFile($theFile,$theLine){
$fp = fopen($theFile, "a");
$orig_size = filesize($theFile);
// Trims all whitespace
$theContents = file_get_contents($theFile);
$strippedContents = str_replace(" ", "", $theContents);
ftruncate($fp, 0);
fwrite($fp, $strippedContents);
// Sets file pointer to the end of the file
fseek($fp, filesize($theFile));
// If this is the first entry in the file, do not add a new line before writing
if($orig_size == 1){
fwrite($fp, "$theLine");
}else{
// If this is not the first entry, write the data on a new line in the file
fwrite($fp, "$theLine");
}
fclose($fp);
}
}
// END CODE
?> | | |
|
| Simple and fast user authentication Categories : PHP, PHP Classes, Authentication | | | Access_user Class - an easy to use system for protecting pages and register users. Categories : PHP, Classes and Objects, Object Oriented, PHP Classes, Authentication | | | .htpassword manager for apache Categories : PHP, PHP Classes, Authentication, Apache | | | Use of bitmasks to represent permissions Categories : PHP, Authentication, Bitwise Operators, Security, PHP Classes | | | Using $PHP_AUTH_USER and $PHP_AUTH_PW to authenticate. Categories : Authentication, PHP | | | very simple ftp class Categories : PHP, PHP Classes, FTP | | | PHP Paypal IPN Integration Class v1.0.0 Categories : PHP, PHP Classes, Payment Gateways | | | Function to remember password Categories : PHP, Authentication, Personalization and Membership | | | PHP4 MYSQL Authentication Script with cookie. Short & Sweet
Categories : Authentication, Apache, Cookies, PHP, MySQL | | | A Timing Class Categories : PHP, PHP Classes, Date Time | | | The class to check load time of your script
VERY usefull for relatively slow applications, but not only.. Categories : PHP, PHP Classes, Debugging | | | Create HTML forms dynamicly using Javascript & PHP Categories : PHP, PHP Classes, Java Script | | | Authorize Me! An authentication script. Categories : MySQL, Databases, Authentication, PHP | | | usercounter class Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables | | | Authentication script to authenticate users in Active Directory through LDAP. Categories : LDAP, Authentication, Cookies, PHP | |
|
|
|