note 29544 added to function.crypt

From: Date: Mon, 17 Feb 2003 08:13:25 +0000
Subject: note 29544 added to function.crypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-44080@lists.php.net to get a copy of this message
Hi, Why isn't the following code working? <?php $auth = false; if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) { $password = $PHP_AUTH_PW; $salt = substr( $password , 0 , 2 ); $enc_pw = crypt( $password, $salt ); $filename = 'file.htpasswd'; $fp = fopen( $filename, 'r' ); $file_contents = fread( $fp, filesize( $filename ) ); fclose( $fp ); $lines = explode ( "\n", $file_contents ); foreach ( $lines as $line ) { list( $username, $password ) = explode( ':', $line ); if($enc_pw == $password && $username == $PHP_AUTH_USER) $auth = true; echo "$enc_pw - $password<br>"; } } if ( ! $auth ) { header( 'WWW-Authenticate: Basic realm="Private"' ); header( 'HTTP/1.0 401 Unauthorized' ); echo 'Authorization Required.'; exit; } else { echo '<P>You are authorized!</P>'; } ?> Greets, Erik. -- http://www.php.net/manual/en/function.crypt.php http://master.php.net/manage/user-notes.php?action=edit+29544 http://master.php.net/manage/user-notes.php?action=delete+29544 http://master.php.net/manage/user-notes.php?action=reject+29544

« previous php.notes (#44080) next »