Get a description of the required password entropy
Cyril Ogana <cogana@gmail.com>
2015-07-18

@return string

@access protected
@final
489146
final protected function  _getPasswordEntropyDescription(){
        $entropyObj = $this->_getUdfEntropy();
        
        $description    = 'The password entropy requires at minimum, the following: ';
        $hasEntropy     = false;
        $isFirstEntropy = false;
        $concatenator   = '';
        
        if ($entropyObj['lowercase']['min_len'] > 0) {
            $lowercaseLen   = $entropyObj['lowercase']['min_len'];
            $description   .= " at least $lowercaseLen lowercase characters";
            $hasEntropy     = true;
            $isFirstEntropy = true;
        }
        
        if ($entropyObj['uppercase']['min_len'] > 0) {
            $isFirstEntropy = $isFirstEntropy === true?  false : true;
            $concatenator   = $isFirstEntropy === true ? ''    : ',';
            $uppercaseLen   = $entropyObj['uppercase']['min_len'];
            $description   .= "$concatenator at least $uppercaseLen uppercase characters";
            $hasEntropy     = true;     
        }
        
        if ($entropyObj['numeric']['min_len'] > 0) {
            $isFirstEntropy = $isFirstEntropy === true ? false : true;
            $concatenator   = $isFirstEntropy === true ? ''    : ',';
            $numericLen     = $entropyObj['numeric']['min_len'];
            $description   .= "$concatenator at least $numericLen numeric characters";
            $hasEntropy     = true;     
        }

        if ($entropyObj['special']['min_len'] > 0) {
            $isFirstEntropy = $isFirstEntropy === true ? false : true;
            $concatenator   = $isFirstEntropy === true ? ''    : ',';
            $specialLen     = $entropyObj['special']['min_len'];
            $description   .= "$concatenator at least $specialLen special characters";
            $hasEntropy     = true;     
        }
        
        if (!($hasEntropy === true)) {
            $description = 'There is no minimum password entropy policy in place';
        }
        
        return $description;
    }
396909
public function getMacKey()
    {
        $key = $this->config['key'];

        $hexStrKey = substr($key, 0, 38);
        $hexFinal = "" . substr($key, 38, 2) . "00";

        $cca0 = ord($hexFinal);

        if ($cca0 > 70 && $cca0 < 97) {
            $hexStrKey .= chr($cca0 - 23) . substr($hexFinal, 1, 1);
        } else {
            if (substr($hexFinal, 1, 1) == "M") {
                $hexStrKey .= substr($hexFinal, 0, 1) . "0";
            } else {
                $hexStrKey .= substr($hexFinal, 0, 2);
            }
        }

        return pack("H*", $hexStrKey);
    }
1291074
public function toString()
    {
        $credentials = array();
        $credentials['E-mail'] = $this->email;
        $credentials['Token'] = $this->token;
        return implode(' - ', $credentials);
    }
348081
public function getPassword() : ?string 
    {
        if ( ! $this->hasPassword()) {
            $this->setPassword($this->getDefaultPassword());
        }
        return $this->password;
    }
830042
def generated_password_entropy(self) -> float:
        """"""
        characters = self._get_password_characters()
        if (
                self.passwordlen is None
                or not characters
        ):
            raise ValueError("Can't calculate the password entropy: character"
                             " set is empty or passwordlen isn't set")

        if self.passwordlen == 0:
            return 0.0

        return calc_password_entropy(self.passwordlen, characters)
1042682
public function getIsEmptyPassword()
    {
        return 
        (!is_string($this->passwordHashAttribute) || empty($this->passwordHashAttribute)) ? 
        true : $this->validatePassword($this->getEmptyPasswordSpecialty());
    }
1182263
public function getPassword()
    {
        $password = strstr($this->getUserInfo(), ':');

        return $password === false ? '' : rawurldecode(substr($password, 1));
    }
88499
public function getMessageString()
    {
        $str = implode(' ', $this->header);
        if (count($this->structuredData)) {
            $str .= ' ' . implode('', $this->structuredData);
        } else {
            $str .= ' ' . self::NILVALUE;
        }
        $str .= ' ' . $this->msg;
        return $str;
    }
884522
public function get_description() {
        // Note that username could be any random user input.
        $username = s($this->other['username']);
        $reasonid = $this->other['reason'];
        $loginfailed = 'Login failed for user';
        switch ($reasonid){
            case 1:
                return $loginfailed." '{$username}'. User does not exist (error ID '{$reasonid}').";
            case 2:
                return $loginfailed." '{$username}'. User is suspended (error ID '{$reasonid}').";
            case 3:
                return $loginfailed." '{$username}'. Most likely the password did not match (error ID '{$reasonid}').";
            case 4:
                return $loginfailed." '{$username}'. User is locked out (error ID '{$reasonid}').";
            case 5:
                return $loginfailed." '{$username}'. User is not authorised (error ID '{$reasonid}').";
            default:
                return $loginfailed." '{$username}', error ID '{$reasonid}'.";

        }
    }
1204824
public function getMessageString()
    {
        $str = $this->pri;
        $str .= implode(' ', $this->header);

        if ($this->message['APP-NAME']) {
            $str .= ' ' . $this->message['APP-NAME'] . ': ' . $this->message['MSG'];
        } else {
            $str .= ' ' . $this->message['MSG'];
        }
        return $str;
    }
942336
public static function salt() {
        $alphabet = self::APRMD5_ALPHABET;
        $salt = '';
        for($i=0; $i<8; $i++) {
            $offset = hexdec(bin2hex(openssl_random_pseudo_bytes(1))) % 64;
            $salt .= $alphabet[$offset];
        }
        return $salt;
    }
539258
public function to_string(): string
	{
		return 'oauth_token=' .
			Util::urlencode_rfc3986($this->key) .
			'&oauth_token_secret=' .
			Util::urlencode_rfc3986($this->secret);
	}
1254632
public function toNQuads()
    {
        $string = '"'.$this->encodeStringLitralForNQuads($this->getValue()).'"';

        if ($this->getLanguage() !== null) {
            $string .= '@'.$this->getLanguage();
        } elseif ($this->getDatatype() !== null) {
            $string .= '^^<'.$this->getDatatype().'>';
        }

        return $string;
    }
1226170
public static function random_password($length = 8)
	{
		$genpass = '';
		$salt = "abchefghjkmnpqrstuvwxyz0123456789";

		srand((double)microtime()*1000000);

		$i = 0;

		while ($i < $length)
		{
			$num = rand() % 33;
			$tmp = substr($salt, $num, 1);
			$genpass = $genpass . $tmp;
			$i++;
		}

		return $genpass;
	}
135284
public function password($length)
    {
        $chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
        $str = '';
        for ($i = 0; $i < $length; ++$i) {
            $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
        }

        return $str;
    }
1103033
public function generateSignature()
    {
        $signatureArray = array();

        // Create a pre-hash string based on the security credentials
        // The order is important
        foreach ($this->validSecurityKeys as $key) {
            if (array_key_exists($key, $this->securityPacket)) {
                array_push($signatureArray, $this->securityPacket[$key]);
            }
        }

        // Add the secret
        array_push($signatureArray, $this->secret);

        // Add the requestPacket if necessary
        if ($this->signRequestData && !empty($this->requestString)) {
            array_push($signatureArray, $this->requestString);
        }

        // Add the action if necessary
        if (!empty($this->action)) {
            array_push($signatureArray, $this->action);
        }

        return $this->hashValue($signatureArray);
    }
519645
static function passwordCharacterTable()
    {
        if ( !empty( $GLOBALS['eZUserPasswordCharacterTable'] ) )
        {
            return $GLOBALS['eZUserPasswordCharacterTable'];
        }
        $table = array_merge( range( 'a', 'z' ), range( 'A', 'Z' ), range( 0, 9 ) );

        $ini = eZINI::instance();
        if ( $ini->variable( 'UserSettings', 'UseSpecialCharacters' ) == 'true' )
        {
            $specialCharacters = '!#%&{[]}+?;:*';
            $table = array_merge( $table, preg_split( '//', $specialCharacters, -1, PREG_SPLIT_NO_EMPTY ) );
        }
        // Remove some characters that are too similar visually
        $table = array_diff( $table, array( 'I', 'l', 'o', 'O', '0' ) );
        $tableTmp = $table;
        $table = array();
        foreach ( $tableTmp as $item )
        {
            $table[] = $item;
        }

        return $GLOBALS['eZUserPasswordCharacterTable'] = $table;
    }