authenticating from login

From: Date: Sun, 20 Apr 2003 00:09:50 +0000
Subject: authenticating from login
Groups: php.general 
Request: Send a blank email to php-general+get-144508@lists.php.net to get a copy of this message
I'm trying to get two variables ( f_user and f_pass ) from a simple form passed to a login.php script that authenticates the username/password pair. I'm kind of new to PHP and not sure if this is the best way to do this: My login.php looks as such: <?php $status = authenticate($f_user, $f_pass); if ($status == 1) { // initiate a session session_start(); // register some session variables session_register("SESSION"); // including the username session_register("SESSION_UNAME"); $SESSION_UNAME = $f_user; // redirect to protected page header("Location: /inner.sanctum.php"); exit(); } else { // redirect to error page header("Location: /error.php?e=$status"); exit(); } function authenticate($user, $pass) { $result = -1; // make sure that the script has permission to read this file! $data = file("/usr/local/passwd"); // iterate through file foreach ($data as $line) { $arr = explode(":", $line); // if username matches // test password if ($arr[0] == $user) { // get salt and crypt() $salt = substr($arr[1], 0, 2); // if match, user/pass combination is correct // return 1 if ($arr[1] == crypt($pass, $salt)) { $result = 1; break; } // otherwise return 0 else { $result = 0; break; } } } // return value return $result; } ?> What UNIX binary would I use to then make the username/passwd line in /usr/local/passwd? I've tried htpasswd -m and PHP's md5(), but both arent working. -Steve

« previous php.general (#144508) next »