Zend - The PHP Company




Passwords

Add Code


smb_auth  

Type: class
Added by: Urkle
Entered: 24/05/2000
Last modified: 08/12/1999
Rating: **** (8 votes)
Views: 8487
Quick little class to authenticate a username/password off of a PDC.


<?
/*
    Author: Edward Rudd <eddie@omegaware.com>
    Based on smb_print by Nathan Cassano <nathan@cjhunter.com>
    Version: 0.1

    Example:

    $test = new smb_auth();
    $test->host = "cannondale";
    $test->smbclient = "/usr/bin/smbclient"; #default is "/usr/bin/smbclient"
    $test->username = "guest";
    $test->password = "dontlook";

    if($test->authenticate() != 0){
        echo "Invalid Authentication";
    }else{
        echo "Authenticated";
    }
*/

class smb_auth {

var 
$host;
var 
$username;
var 
$password;
var 
$smbclient "/usr/bin/smbclient";

function 
smb_auth()
{
    return 
0;
}

function 
authenticate()
{
    
/* Make sure smbclient path is correct */
    
if(!is_executable($this->smbclient)){
        die(
"Error: '$this->smbclient' invalid smbclient path");
    }

    
/* create the shell script */ 
    
$script =  "$this->smbclient //$this->host/IPC$ $this->password "
        
."-U $this->username -c 'quit' > /dev/null 2>&1";

    
$stuff system ($script,$result);

    return 
$result;
}

}
?>


Usage Example


<?
include "smb_auth.php";
$test = new smb_auth();
$test->host "cannondale";
$test->smbclient "/usr/bin/smbclient"
$test->username "guest";
$test->password "dontlook";

if(
$test->authenticate() != 0){
    echo 
"Invalid Authentication";
}else{
    echo 
"Authenticated";
}
?>


Rate This Script





Search



This Category All Categories