"Can this be done in php"
Sure, just encrypt the password and compare it with the password in the server's password file.
But a script like that would be 'unsafe' to say the least. You're basically opeing up a 'mastermind' interface to your server's account files. Any hacker can try a brute force attack and all you'll notice is that your webserver is busier than normal (and not even that if the hacker is carefull)
Also, HTTP is plaintext, which means that the 'better than average' hacker can read-along with your webtraffic and filter out all the user's names and passwords, and he even gets a message to verify which passwords work and which don't.
Not smart.