Phpcheckpass

FusionDirectory hooks are meant to be used with shell or perl script, but it can be done with php scripts too. This is a simple php sample to see how to read STDIN to use with FusionDirectory hooks.

#!/usr/bin/php
<?

    /** 
     * Script to validate a password for FusionDirectory
     * - Example: The first 6 chars must be numeric
     *
     * @param string username
     * @param string new password
     * @return mixed null if ok, error message otherwise
     */
    // Reads STDIN to get parameters
    $arrArgs = array();
    while($input = trim(fgets(STDIN))){
        $arrTmp = explode(':', $input);
        $arrArgs[trim($arrTmp[0])] = trim($arrTmp[1]);
    }

    // Check number of parameters
    if(count($arrArgs) != 3){ 
        echo "ERR: Wrong number of parameters.\n";
        exit(0);
    }   

    // Check if the first 6 chars are numeric by using a regular expression
    $strExpReg = '/^(\d{6}).*/';
    if(!preg_match($strExpReg, $arrArgs['new_password'])){
        echo "ERR: The first 6 chars must be numeric!\n";
    }   
    exit(0);

?>
en/documentation_howto/php_check_password.txt · Last modified: 2019/07/23 15:30 by Benoit Mortier
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0