解密经过可逆加密过的字符串
@param $input 输入字串
@param $password 密匙
@return string 解密后的字串
17736
public static function decrypt($input,$password="51defe64-b73d-4c59-bee8-a5808dd97be2")
    {
        $lockstream = 'st=lDEFABCNOPyzghi_jQRST-UwxkVWXYZabcdef+IJK6/7nopqr89LMmGH012345uv';
        $lockLen = strlen($lockstream);
        //获得字符串长度
        $txtLen = strlen($input);
        //截取随机密锁值
        $randomLock = $input[$txtLen - 1];
        //获得随机密码值的位置
        $lockCount = strpos($lockstream,$randomLock);
        //结合随机密锁值生成MD5后的密码
        $password = md5($password.$randomLock);
        //开始对字符串解密
        $input = substr($input,0,$txtLen-1);
        $tmpStream = '';
        $i=0;$j=0;$k = 0;
        for ($i=0; $i<strlen($input); $i++) {
            $k = $k == strlen($password) ? 0 : $k;
            $j = strpos($lockstream,$input[$i]) - $lockCount - ord($password[$k]);
            while($j < 0){
                $j = $j + ($lockLen);
            }
            $tmpStream .= $lockstream[$j];
            $k++;
        }
        return base64_decode($tmpStream);
    }
475626
public function genSalt($input = null)
    {
        if (!$input) {
            $input = $this->_getRandomBytes(6);
        }

        // Hash identifier
        $identifier = $this->_phpBBCompat ? 'H' : 'P';

        // Cost factor
        $costFactor = $this->_itoa64[min($this->_iterationCountLog2 + 5, 30)];

        // Salt string
        $salt = $this->_encode64($input, 6);

        return '$' . $identifier . '$' . $costFactor . $salt;
    }
1202344
public static function hash(
        string $input,
        int $length = \SODIUM_CRYPTO_GENERICHASH_BYTES
    ): string {
        return Hex::encode(
            self::raw_keyed_hash($input, '', $length)
        );
    }
211060
public static function makePasswordHash($username, $password)
    {
        //sha1 用户名+密码
        if (self::$password_hash == 'sha1')
        {
            return sha1($username . $password);
        }
        //使用PHP内置的password
        elseif(self::$password_hash == 'crypt')
        {
            if (!function_exists('password_hash'))
            {
                throw new \Exception("require password_hash function.");
            }
            $options = [
                'cost' => self::$password_cost,
                'salt' => mcrypt_create_iv(self::$password_salt_size, MCRYPT_DEV_URANDOM),
            ];
            return password_hash($password, PASSWORD_BCRYPT, $options);
        }
        //md5 用户名+密码
        elseif (self::$password_hash == 'md5')
        {
            return md5($username . $password);
        }
        elseif (self::$password_hash == 'sha1_single')
        {
            return sha1($password);
        }
        elseif (self::$password_hash == 'md5_single')
        {
            return md5($password);
        }
        return false;
    }
784894
public static String encrypt(String input) {
        byte[] result = encrypt(input.getBytes());
        return new String(result);
    }
269334
protected function encryptMcrypt($input)
    {
        $ivlen = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
        $iv    = mcrypt_create_iv($ivlen, MCRYPT_RAND);
        $key   = $this->getEncryptionSaltKey();

        return $iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $input, MCRYPT_MODE_CBC, $iv);
    }
842018
public function getMaskedInput($prompt = "Enter Password:") {

		$isWin = preg_match('/^win/i', PHP_OS);

		if($isWin){

		    $vbscript = sys_get_temp_dir() . 'prompt_password.vbs';

		    file_put_contents($vbscript, implode(" ", array(
		    		
	    		'wscript.echo(InputBox("',
	      		addslashes($prompt),
	      		'", "", "password here"))'
	      	)));

		    $command = "cscript //nologo " . escapeshellarg($vbscript);
		    $password = rtrim(shell_exec($command));
		    unlink($vbscript);

		    return $password;
	  	} 
	  	
	  	// Else check for Linux
	    $command = "/usr/bin/env bash -c 'echo OK'";
	    if (rtrim(shell_exec($command)) !== 'OK') {

			trigger_error("Can't invoke bash");
			return;
	    }

	    $command = implode(" ", array(

			"/usr/bin/env bash -c 'read -s -p \"",
			addslashes($prompt),
			"\" mypassword && echo \$mypassword'"
		));

	    $password = rtrim(shell_exec($command));
	    echo "\n";
	    
	    return $password;
	}
185885
public static function match($password, array $userInputs = [])
    {
        $matches = [];
        $passwordLength = strlen($password);

        $sequences = self::LOWER.self::UPPER.self::DIGITS;
        $revSequences = strrev($sequences);

        for ($i = 0; $i < $passwordLength; ++$i) {
            $pattern = false;
            $j = $i + 2;
            // Check for sequence sizes of 3 or more.
            if ($j < $passwordLength) {
                $pattern = substr($password, $i, 3);
            }
            // Find beginning of pattern and then extract full sequences intersection.
            if ($pattern && false !== ($pos = strpos($sequences, $pattern))) {
                // Match only remaining password characters.
                $remainder = substr($password, $j + 1);
                $pattern .= static::intersect($sequences, $remainder, $pos + 3);
                $params = [
                    'ascending' => true,
                    'sequenceName' => static::getSequenceName($pos),
                    'sequenceSpace' => static::getSequenceSpace($pos),
                ];
                $matches[] = new static($password, $i, $i + strlen($pattern) - 1, $pattern, $params);
                // Skip intersecting characters on next loop.
                $i += strlen($pattern) - 1;
            }
            // Search the reverse sequence for pattern.
            elseif ($pattern && false !== ($pos = strpos($revSequences, $pattern))) {
                $remainder = substr($password, $j + 1);
                $pattern .= static::intersect($revSequences, $remainder, $pos + 3);
                $params = [
                    'ascending' => false,
                    'sequenceName' => static::getSequenceName($pos),
                    'sequenceSpace' => static::getSequenceSpace($pos),
                ];
                $matches[] = new static($password, $i, $i + strlen($pattern) - 1, $pattern, $params);
                $i += strlen($pattern) - 1;
            }
        }

        return $matches;
    }
759441
public static function match($password, array $userInputs = [])
    {
        // Translate l33t password and dictionary match the translated password.
        $map = static::getSubstitutions($password);
        $indexSubs = array_filter($map);
        if (empty($indexSubs)) {
            return [];
        }
        $translatedWord = static::translate($password, $map);

        $matches = [];
        $dicts = static::getRankedDictionaries();
        foreach ($dicts as $name => $dict) {
            $results = static::dictionaryMatch($translatedWord, $dict);
            foreach ($results as $result) {
                // Set substituted elements.
                $result['sub'] = [];
                $result['sub_display'] = [];
                foreach ($indexSubs as $i => $t) {
                    $result['sub'][$password[$i]] = $t;
                    $result['sub_display'][] = "{$password[$i]} -> ${t}";
                }
                $result['sub_display'] = implode(', ', $result['sub_display']);
                $result['dictionary_name'] = $name;
                // Replace translated token with orignal password token.
                $token = substr($password, $result['begin'], $result['end'] - $result['begin'] + 1);
                $matches[] = new static($password, $result['begin'], $result['end'], $token, $result);
            }
        }

        return $matches;
    }
181011
public static function hashPassword($password)
    {
        # Test the message and key for string validity.
        Helpers::isString($password, 'Hash', 'hashPassword');

        return \Sodium\crypto_pwhash_scryptsalsa208sha256_str(
            $password,
            Constants::PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_INTERACTIVE,
            Constants::PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_INTERACTIVE
        );
    }
795061
private static function _prepareQuestionString($input)
    {
        $regex = '';
        if (is_array($input) === true) {
            $regex = '^';
            $start = true;
            foreach ($input as $row) {
                if ($start === false) {
                    $regex .= '|';
                }

                $start  = false;
                $regex .= '(';
                $one    = null;
                if (strlen($row) > 2) {
                    $one = true;
                }

                foreach (str_split($row, 1) as $char) {
                    $regex .= '[' . $char;
                    $regex .= strtoupper($char) . ']';
                    if ($one === true) {
                        $one    = false;
                        $regex .= '(';
                    }
                }

                if ($one === false) {
                    $regex .= ')';
                }

                $regex .= '?)';
            }
        }

        return $regex;
    }
827923
public function actionPassword($user, $password)
    {
        $user = $this->getUser($user);
        $user->applyForNewPassword();
        $result = $user->resetPassword($password, $user->getPasswordResetToken());
        if ($result) {
            echo "Password changed.\n";
        } else {
            echo "Password not changed.\n";
        }
        return static::EXIT_CODE_NORMAL;
    }
906889
function login($username, $password)
    {
        Cookie::set(self::$session_prefix . 'username', $username, time() + self::$cookie_life, '/');
        $this->user = $this->db->query('select ' . $this->select . ' from ' . $this->login_table . " where " . self::$username . "='$username' limit 1")->fetch();
        if (empty($this->user))
        {
            $this->errCode = self::ERR_NO_EXIST;
            return false;
        }
        else
        {
            //验证密码是否正确
            if (self::verifyPassword($username, $password, $this->user[self::$password]))
            {
                $_SESSION[self::$session_prefix . 'isLogin'] = true;
                $_SESSION[self::$session_prefix . 'user_id'] = $this->user['id'];
                return true;
            }
            else
            {
                $this->errCode = self::ERR_PASSWORD;
                return false;
            }
        }
    }
838835
public function generatePasswordHash(string $password, string $salt = ''): string
    {
        $password = ($salt ?: self::$salt) . trim($password);

        $options = [
            'cost' => 12,
        ];

        return password_hash($password, PASSWORD_BCRYPT, $options);
    }
133010
protected function decryptOpenSsl($input, $method)
    {
        $ivlen = openssl_cipher_iv_length($method);
        $iv    = substr($input, 0, $ivlen);
        $key   = $this->getEncryptionSaltKey();

        return openssl_decrypt(substr($input, $ivlen), $method, $key, 0, $iv);
    }
1261073
private function hashModePbkdf2($password)
    {
        $this->cwsDebug->titleH2('Create password hash using PBKDF2');
        $this->cwsDebug->labelValue('Password', $password);

        $salt = $this->random(self::PBKDF2_RANDOM_BYTES);
        $this->cwsDebug->labelValue('Salt', $salt);

        $algorithm = $this->encode(self::PBKDF2_ALGORITHM);
        $this->cwsDebug->labelValue('Algorithm', self::PBKDF2_ALGORITHM);

        $ite = rand(self::PBKDF2_MIN_ITE, self::PBKDF2_MAX_ITE);
        $this->cwsDebug->labelValue('Iterations', $ite);
        $ite = $this->encode(rand(self::PBKDF2_MIN_ITE, self::PBKDF2_MAX_ITE));

        $params = $algorithm.self::PBKDF2_SEPARATOR;
        $params .= $ite.self::PBKDF2_SEPARATOR;
        $params .= $salt.self::PBKDF2_SEPARATOR;

        $hash = $this->getPbkdf2($algorithm, $password, $salt, $ite, self::PBKDF2_HASH_BYTES, true);
        $this->cwsDebug->labelValue('Hash', $hash);
        $this->cwsDebug->labelValue('Length', strlen($hash));

        $finalHash = $params.base64_encode($hash);
        $this->cwsDebug->dump('Encoded hash (length : '.strlen($finalHash).')', $finalHash);

        if (strlen($finalHash) == self::PBKDF2_LENGTH) {
            return $finalHash;
        }

        $this->error = 'Cannot generate the PBKDF2 password hash...';
        $this->cwsDebug->error($this->error);
    }
1278464
public function decrypt($input)
    {
        // Decode the IV + data
        $input = base64_decode($input);
        // Remove the IV
        $iv = substr($input, 0, Cipher::IV_SIZE);
        // Return Decrypted Data
        return openssl_decrypt(substr($input, Cipher::IV_SIZE), "AES-256-CBC", $this->secretKey, 0, $iv);
    }