WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : .htpasswd class
Categories : PHP, PHP Classes, Authentication Click here to Update Your Picture
Scott Newman
Date : Jun 11th 2005
Grade : 2 of 5 (graded 7 times)
Viewed : 11312
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Scott Newman
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?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