htpasswd and php
by AndyMac
I thought I could help some folks with some basic web auth functions.
I often find that I want to check out whether a user has the permissions to do something, but might not want to generate htaccess rules for each and every script. Instead, I want my server side scripts to be able to do these tests and continue or fail correctly.
To that end, you need to be able to read the .htpasswd file.
I put together a real quick htpasswd “helper” file that contains a few functions for adding users, changing passwords, checking whether a user has correctly entered information, and things like that.
For this particular example, we want to take a username and a password (in plain text, which is not as safe … you could encrypt it before you send the information, but then, if you’re using htpasswd, you’re already somewhat on the insecure side of “locked down”) and ask whether the username and password are in the htpasswd file.
function validate($file, $username, $password) {
$lines = file($file);
for ($ii = 0; $ii < count($lines); $ii++) {
if (preg_match("/:/",$lines[$ii])) {
$lines[$ii] = trim($lines[$ii]);
list($user,$pass) = explode(":",$lines[$ii]);
if ($user == $username) {
$password = crypt(rtrim($password),substr($pass,0,2));
if ($pass == $password) {
return true;
} else {
return false;
}
}
}
}
}
The key here is the “crypt” command that encrypts the password using the first two letters of the password as the seed.
Give it a shot, let me know how it works for you!
Find the time of day in Minecraft
by AndyMac
Want to find out what time it is in your minecraft server? Are you deep underground, or just don’t want to log in when it’s dark outside? Want to post that information to a web server? No problem! It just takes some php on your server to find out the time (perl or other languages will work just as well) and some javascript to display everything nicely!

Home Website: Get it going with DynDNS!
by AndyMac
Last week, I told you about setting up a Minecraft server. I suggested we set up a LAMP server, but this week is the beginning of why that’s important! This week, we’re going to use DynDNS to get a domain name that will point to your LAMP server.
LAMP stands for Linux, Apache, MySQL, PhP, and I won’t go into the details of how to set it up, because there’s some great tutorials: this one, for example. (Continue Reading...)
Starting a Minecraft server
by AndyMac
Minecraft, for those of you not yet in the know is a cool new indie game that’s getting a lot of press. So much press, that I checked it out. (Continue Reading...)
Storm8 Income Calculator
by AndyMac
So my wife and I got hooked on Storm8′s iMobsters on our Android phones. Because of that, I wanted to know which RealEstate to buy to maximize my income. I built a quick spreadsheet, looked around online, and realized I didn’t see any other calculators that were free, open source, and … well, I didn’t see any that were free and open source!
So here we go! made one real quick that should work on any Storm8 game (Continue Reading...)
Custom Gallery Viewer
by AndyMac
We built a custom gallery viewer because we needed a few specific things. So here it is inside wordpress! You’re free to use it anywhere you like!
Functionally, it has thumbnails and full pictures (making it fast to load), a lightbox with an image loader, lets you include titles, text, image tags and a link with every image if you want it, lets you order the pictures however you like, resizes thumbnails, is adjustable for number of images on the page, creates multiple pages if necessary, and should (for the most part) drop in to any site easily. (Continue Reading...)