corz.org uses cookies to remember that you've seen this notice explaining that corz.org uses cookies, okay!
pajamas..
php and javascript advanced md5 authentication system
The connexion between "pajamas", which is an acronym for "php and javascript advanced md5 authentication system" and an actual pair of "Pyjamas" is that when you feel secure, you sleep better. Of course the words sound identical, too.
pajamas began as an attempt to create a more secure login using client-side hashing, which is one-way encryption, and as a demonstration, mainly for other web-coders, to two enormous security holes in all-too-common existence..
The first exists when folk use "public" browsers. Often the username and password are stored on the machine, and can be re-used, even by accident, by other members of the public. Clearly this presents a problem, and one which, for some reason, most people like to forget and/or ignore. Probably, like me, they realized it would need to be done with JavaScript, and then ran in the opposite direction.
The second hole is more obvious, and that is the plain text password travelling freely across the wires. This one has received more worldwide attention, but it's still ignored in most php web applications. There are literally hundreds of articles out there describing how to store a user's password using all manner of weird and wonderful algorithms, to protect it from "unauthorised database access", or "unauthorised server access", and yet still expecting the password to arrive in plain text. GUYS!
If your database isn't secure you are in trouble. Same for your filesystem. These are places over which you have control. The place where you certainly don't have control, ever, is the internet. And the moment that packet of data leaves the user's presumably safe environment it's fair game. Its contents could be stored on any one of the many nodes between server and client, dubious proxy "servers" could scan it, on poorly configured servers (most) passwords will show up on other server's referrer logs, etc. There it is, your plain-text password, travelling around the internet in a bundle of other useful plain text information, like the URL of the so-called secure login page, probably your username. No! This is insane!
pajamas takes an entirely different approach. The password is securely hashed before being sent over the wires. Now, not only is interception no longer a problem (it's impossible to retrieve the password from the hash in the given time-frame, even a very much longer time-frame), but public browsers can't save or cache it, either*, being a one-shot mish-mash of your password and some random generated string. Each time you login, it's completely different.
With pajamas, the only places the password ever exists in the clear are in your presumably secure server environment, and the presumably secure user's brain. This password is only protecting access to this server's content; ergo, breaching the web server breaches the user's "protected" data, anyway. To my reckoning, it would be considerably more difficult to compromise a modern web server and get root, than it is to search some log for the phrase "password".
Which strategy is best? You decide.
Since its birth back in 2004, pajamas spent quite a long time lying fairly dormant, yet working away quietly in the background as a highly useful authentication script. More recently, pajamas has grown into a rather neat modular authentication system, and the old "pj" module has essentially become one of its plug-ins. There's also a "plain" plugin that retains many of the good features of pj, but without the client-side hashing, for situations where JavaScript isn't available (On The Moon, maybe!). pj's client-side hashing is made possible with the excellent JavaScript functions provided by Paul Johnston's javascript MD5 code.
You can enjoy my wee "protected" image gallery, and try-out pajamas at the same time, here. If you'd like to ask questions, give feedback, enlighten me, etc, you can do that at the bottom.
The default module on corz.org uses HMAC-SHA256 over HTTPS. The browser signs a fresh server challenge using Web Crypto. See the SHA256 setup example.
There is also a sha1 pajamas plug-in called "shaggie", which is currently available only inside my other packages (e.g. the distro machine), feel free to download and play around with it; get back to me if you find any issues, thanks.
Here's the current pajamas code..
(of course, most of the good stuff is inside the modules!)
At least, this is the expected behaviour - currently, as far as I know, Opera saves the *typed* password, rather than the *sent* password, effectively defeating all forms of client-side password hashing strategy, dudes! - I've figured out a way around this, by the way, which will hopefully hit the code stage for my upcoming "shaggie" pajamas module. Take it easy!
I don't know what a standard installation is, if such a thing even exists, and without more in the way of real error messages, your pj troubles are also a mystery to me.
Feel free to mail me whole screeds of log output, php error messages, copies of pj, between now and when I wake up, tomorrow. If there's only a single error message, or a small amount of useful data, drop it here.
I didn't realize there was "needed stuff" for pajamas, aside from basic php4+. But there may well be. Again, more details welcome.
You've seen the readme link at the top of the page, right?
;o)
ps. iirc, the latest pajamas release, currently, is inside the distro machine beta (elsewhere onsite), there are differences that may affect how the old release demo works, but pj itself works great. check the implementation in the distro machine beta.
dumpydooby - 05.12.08 6:03 am
There seems to be a bug with PAJAMAS on this system I'm using. It doesn't work on my own site where I've implemented it, and even your demo doesn't work. I don't know the details of the system I'm on, but I can give you the UserAgent value:
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9) Gecko/2008061004 Firefox/3.0
corz - 05.12.08 6:15 am
If you can't get even the demo to work on your site, there is clearly something very wrong. You user agent string probably has nothing to do with it. Check your php error log and note any related errors, post them here. You might also want to download debug-report.php, which will spit out all sort of useful information, let you know if php sessions are working correctly and more.
Also, does the demo work for you here at corz.org? If not, it's possible there's something up with your browser.
;o)
dumpydooby - 06.12.08 8:58 pm
That's just the thing. I have PAJAMAS working just fine on my site. It works on every browser I've tried. The demo here on corz.org also works in every browser.
The problem that I was pointing out was only related to that specific system I was on the other night. I was in a classroom and I was trying to show PAJAMAS to a web development professor at my school. PAJAMAS didn't work on the computer that I was using (which is why I posted the UserAgent information), and I figured you should know what browser and OS I was using so that you could replicate the problem and see if you could figure out what was wrong (or you might know if there is a potential compatibility issue between MacOSX w/Firefox 3 and your script).
I'll tell you what, though. Next time I go into that classroom (which isn't often since I don't actually have any classes in there), I'll set up a test page for PAJAMAS on my site, and I'll unmask the password to see if there is an issue that stands out right away. I'll also try using one of the alternative javascript-based md5 scripts out there in cyberland.
corz - 06.12.08 9:23 pm
It's amazing how little feedback I get about pajamas, yet I keep coming across it, and recommendations for it, all over the place. No one ever thinks to mail me and say, "Hey! I got pajamas working on X server v0.x, works great. Thanks!", or anything like that. What I mean is, good to hear, ta.
As to the issue on that machine, were there any specific errors? I've noticed hits in my error log recently with FF3 looking for resources in totally the wrong place; I must check if it was on OSX, perhaps the combo has issues. Probably more useful than unmasking the password (if it changes length, the javascript part is probably working fine, probably), would be to have a peek at the session variables. See exactly what's been stored.
The debug script I mentioned in my previous post is excellent for this. I also have a session viewer script kicking around (it's not available for download (at least until I can get around to doing a safe online demo version - it has a drop-down of all available sessions, very handy)) mail me if you want a copy.
I'm curious, why were you showing to the professor? You can tell how feedback-starved I am about pj!
Another thing you might want to try is the sha1 module. I don't think it ever made it to an official pj release, but there will be a copy inside the most recent distro machine download, for sure, and elsewhere onsite.
Lastly, if other md5 scripts can slot into pajamas, that's something I'd be keen to know about! But any data you have is useful. Cheers!
;o)
jdmfontz - 08.01.09 4:48 pm
This sounds neat. However, how do you get around the problem presented by G Funk?
" Re: Response to G Funk
-----------------------------------------
Well G Funk, it's a mind-bender, that's for sure!
At first glance it seems reasonable to store the password as an MD5 on the server, but in reality, all we have done is replaced the password with an MD5 of itself. In other words, you could authenticate by simply knowing the MD5, just as easily as you can by knowing the actual password.
When I first put pajamas together, I wrestled with this for some time! "
For this to work you would need to md5 a random string along with the password. But them how do you get the server to know what that is?
This is where PKI comes useful. Client uses server public key to create the hash, server opens hash with private key, etc.
corz - 18.01.09 6:00 pm
I believe I already answered that.
;o)
Chris - 30.01.10 5:43 pm
I LOVE your pajamas! This is a very well thought out and useful script. Of course I found this a day after I figured out that you can use http auth with an SSL certificate to encrypt your password while it travels over the network =p
Why is it that the simple demo fails but the regular demo does not?
I added a php.ini with the following to /demo/, /demo/inc/, and /demo/inc/pajamas/ too no avail...
[php]
session.use_trans_sid = 0
Any idears?
Ensure you aren't manually setting php_value session.name. I have seen this interfere with some installations. ;o)
Will - 01.03.10 3:09 am
A bit of a newb question, but I got here from a google search on htpasswd.
Is there any way to protect a Directory using pajamas, the way you would with .htaccess+.htpasswd?
The readme was a little more technical than my level. Thx!
corz - 04.03.10 3:14 pm
Yes, simply drop the whole lot into the directory you want to protect - or else put it elsewhere on your site and set that path in the preferences inside pajamas.
Remember to set the name of the main pajamas page to your default document (usually index.php or similar). That way, whenever someone enters that directory, they always get pajamas, and not a directory listing.
Download the zip. The examples in the demo folder (inside the pajamas zip) should get you started. Open the simple demo (simple.php) in a text editor. It's basically this..
<?php include 'inc/pajamas/pajamas.php'; $auth = new pajamasSimple('wadeva');
if ($auth->auth_user()) { // Authorised here } else { // not authorised here. } ?>
With that simple code you can protect anything (well, web resources!).
;o)
ps. depending on the contents of the directory, you may want to opt for something with more features. Check out the distro machine, which includes pajamas.
Welcome to the comments facility!
I don't know what a standard installation is, if such a thing even exists, and without more in the way of real error messages, your pj troubles are also a mystery to me.
Feel free to mail me whole screeds of log output, php error messages, copies of pj, between now and when I wake up, tomorrow. If there's only a single error message, or a small amount of useful data, drop it here.
I didn't realize there was "needed stuff" for pajamas, aside from basic php4+. But there may well be. Again, more details welcome.
You've seen the readme link at the top of the page, right?
;o)
ps. iirc, the latest pajamas release, currently, is inside the distro machine beta (elsewhere onsite), there are differences that may affect how the old release demo works, but pj itself works great. check the implementation in the distro machine beta.
There seems to be a bug with PAJAMAS on this system I'm using. It doesn't work on my own site where I've implemented it, and even your demo doesn't work. I don't know the details of the system I'm on, but I can give you the UserAgent value:
Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9) Gecko/2008061004 Firefox/3.0
If you can't get even the demo to work on your site, there is clearly something very wrong. You user agent string probably has nothing to do with it. Check your php error log and note any related errors, post them here. You might also want to download debug-report.php, which will spit out all sort of useful information, let you know if php sessions are working correctly and more.
You can get that here.
Also, does the demo work for you here at corz.org? If not, it's possible there's something up with your browser.
;o)
That's just the thing. I have PAJAMAS working just fine on my site. It works on every browser I've tried. The demo here on corz.org also works in every browser.
The problem that I was pointing out was only related to that specific system I was on the other night. I was in a classroom and I was trying to show PAJAMAS to a web development professor at my school. PAJAMAS didn't work on the computer that I was using (which is why I posted the UserAgent information), and I figured you should know what browser and OS I was using so that you could replicate the problem and see if you could figure out what was wrong (or you might know if there is a potential compatibility issue between MacOSX w/Firefox 3 and your script).
I'll tell you what, though. Next time I go into that classroom (which isn't often since I don't actually have any classes in there), I'll set up a test page for PAJAMAS on my site, and I'll unmask the password to see if there is an issue that stands out right away. I'll also try using one of the alternative javascript-based md5 scripts out there in cyberland.
It's amazing how little feedback I get about pajamas, yet I keep coming across it, and recommendations for it, all over the place. No one ever thinks to mail me and say, "Hey! I got pajamas working on X server v0.x, works great. Thanks!", or anything like that. What I mean is, good to hear, ta.
As to the issue on that machine, were there any specific errors? I've noticed hits in my error log recently with FF3 looking for resources in totally the wrong place; I must check if it was on OSX, perhaps the combo has issues. Probably more useful than unmasking the password (if it changes length, the javascript part is probably working fine, probably), would be to have a peek at the session variables. See exactly what's been stored.
The debug script I mentioned in my previous post is excellent for this. I also have a session viewer script kicking around (it's not available for download (at least until I can get around to doing a safe online demo version - it has a drop-down of all available sessions, very handy)) mail me if you want a copy.
I'm curious, why were you showing to the professor? You can tell how feedback-starved I am about pj!
Another thing you might want to try is the sha1 module. I don't think it ever made it to an official pj release, but there will be a copy inside the most recent distro machine download, for sure, and elsewhere onsite.
Lastly, if other md5 scripts can slot into pajamas, that's something I'd be keen to know about! But any data you have is useful. Cheers!
;o)
This sounds neat. However, how do you get around the problem presented by G Funk?
" Re: Response to G Funk
-----------------------------------------
Well G Funk, it's a mind-bender, that's for sure!
At first glance it seems reasonable to store the password as an MD5 on the server, but in reality, all we have done is replaced the password with an MD5 of itself. In other words, you could authenticate by simply knowing the MD5, just as easily as you can by knowing the actual password.
When I first put pajamas together, I wrestled with this for some time! "
For this to work you would need to md5 a random string along with the password. But them how do you get the server to know what that is?
This is where PKI comes useful. Client uses server public key to create the hash, server opens hash with private key, etc.
I believe I already answered that.
;o)
I LOVE your pajamas! This is a very well thought out and useful script. Of course I found this a day after I figured out that you can use http auth with an SSL certificate to encrypt your password while it travels over the network =p
Why is it that the simple demo fails but the regular demo does not?
I added a php.ini with the following to /demo/, /demo/inc/, and /demo/inc/pajamas/ too no avail...
Any idears?
A bit of a newb question, but I got here from a google search on htpasswd.
Is there any way to protect a Directory using pajamas, the way you would with .htaccess+.htpasswd?
The readme was a little more technical than my level. Thx!
Yes, simply drop the whole lot into the directory you want to protect - or else put it elsewhere on your site and set that path in the preferences inside pajamas.
Remember to set the name of the main pajamas page to your default document (usually index.php or similar). That way, whenever someone enters that directory, they always get pajamas, and not a directory listing.
Download the zip. The examples in the demo folder (inside the pajamas zip) should get you started. Open the simple demo (simple.php) in a text editor. It's basically this..
<?php
include 'inc/pajamas/pajamas.php';
$auth = new pajamasSimple('wadeva');
if ($auth->auth_user()) {
// Authorised here
} else {
// not authorised here.
}
?>
With that simple code you can protect anything (well, web resources!).
;o)
ps. depending on the contents of the directory, you may want to opt for something with more features. Check out the distro machine, which includes pajamas.