Generates auth. key
@param  string $username Username
@param  string $password Password
@param  string $nonce Nonce
@return string           MD5 hash
545793
public static function getAuthKey($username, $password, $nonce)
    {
        return md5($nonce . $username . md5($username . ':mongo:' . $password));
    }
736494
private function createUser($username, $password)
    {
        $user = new UserInformation(
            [
                'username' => $username,
                'acl'      => UserInformationInterface::ROLE_ALL
            ]
        );

        $user->set('password', $this->get('security.password_encoder')->encodePassword($user, $password));

        $user = $this->get('tenside.user_provider')->addUser($user)->refreshUser($user);

        return $user;
    }
1189030
public function login($username, $password)
  {
    $this->execute("login", array("client_login_name" => $username, "client_login_password" => $password));
    $this->whoamiReset();

    $crypt = new TeamSpeak3_Helper_Crypt($username);

    $this->setStorage("_login_user", $username);
    $this->setStorage("_login_pass", $crypt->encrypt($password));

    TeamSpeak3_Helper_Signal::getInstance()->emit("notifyLogin", $this);
  }
743292
public static String createOpaque(final String domain, final String nonce) {
        return DigestUtils.md5Hex(domain + nonce);
    }
641223
public function decrypt($data, $key = null, $nonce = null)
    {
        $plain = parent::decrypt($data, $key, $nonce);

        $key = (string) $key;
        $nonce = (string) $nonce;

        $this->memzero($data);
        $this->memzero($key);
        $this->memzero($nonce);

        return $plain;
    }
1014416
protected function generateNonce()
    {
        // generate a random string
        $bits   = 256;
        $bytes  = ceil($bits / 8);
        $string = '';
        for ($i = 0; $i < $bytes; $i++) {
            $string .= chr(mt_rand(0, 255));
        }

        // sha1 hash
        return hash('sha1', $string);
    }
295247
protected function adminLogin($username, $password)
    {
        $hash = $this->getPasswordHash()->hash($password);

        $user = $this->getEntityManager()->getRepository('User')->findOne([
            'whereClause' => [
                'userName' => $username,
                'password' => $hash,
                'type' => ['admin', 'super-admin']
            ]
        ]);

        return $user;
    }
761506
public function checkUserCredentials($username, $password)
    {
        if ($user = $this->getUser($username)) {
            return $this->checkPassword($user, $password);
        }

        return false;
    }
648656
def generate_key_data_from_nonce(server_nonce, new_nonce):
    """"""
    server_nonce = server_nonce.to_bytes(16, 'little', signed=True)
    new_nonce = new_nonce.to_bytes(32, 'little', signed=True)
    hash1 = sha1(new_nonce + server_nonce).digest()
    hash2 = sha1(server_nonce + new_nonce).digest()
    hash3 = sha1(new_nonce + new_nonce).digest()

    key = hash1 + hash2[:12]
    iv = hash2[12:20] + hash3 + new_nonce[:4]
    return key, iv
139925
public function authenticate($username, $password) {

    // Get some things.
    $client = $this->getClient();
    $parameters = $this->getAuthParams();
    $endpoint = $this->getEndpoint();
    $code = NULL;

    $response = $client->get($endpoint,
      ['query' => $parameters, 'auth' => [$username, $password]]
    );

    $code = $response->getStatusCode();
    $this->setLastResponse($response);

    // @todo: handle non 200 responses with error logging.
    switch ($code) {
      case '200':
        $body = $response->getBody();
        $json = json_decode($body->getContents());
        if (empty($json)) {
          throw new \Exception("Could not get JSON from body.");
        }
        $this->setAuthApiToken($json->access_token);
        $this->setAuthApiTokenExpires($json->expires_in);
        break;
    }

    return $this;
  }
967562
public function generateKey($name)
    {
        if (strlen($name) === 0) {
            throw new SecurityException('Required name argument was empty', 1334215474);
        }
        $password = UtilityAlgorithms::generateRandomString($this->passwordGenerationLength);
        $this->persistKey($name, $password);
        return $password;
    }
986921
public function generateNonce()
    {
        $data = function_exists('random_bytes') ? random_bytes(16) : openssl_random_pseudo_bytes(16);
        $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
        $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10

        return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
    }
858809
public function getNonce()
    {
        if ($this->nonce !== '') {
            return $this->nonce;
        }
        $this->nonce = md5(uniqid(rand(), true));
        return $this->nonce;
    }
694869
public function basicAuth($username, $password)
    {
        $this->auth = new BasicAuth($username, $password);
        return $this->auth;
    }
294278
public function authenticate($username, $password)
	{
		$this->debug->groupCollapsed(__METHOD__);
		$return = false;
		$users = $this->search(array(
			'username'	=> $username,
			'email'		=> $username,
		));
		if ($users && $this->verifyPassword($password, $users[0]['password'])) {
			$this->debug->info('login success');
			$this->log('login', $users[0]['userid']);
			$return = $users[0]['userid'];
		} else {
			$this->debug->warn('login failed');
			$userid = $users
				? $users[0]['userid']
				: null;
			$this->log('loginFail', $userid);
		}
		$this->debug->groupEnd();
		return $return;
	}
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;
    }
338584
protected function generateNonce()
    {
        $expiryTime = microtime(true) + $this->getConfig('nonceLifetime');
        $secret = $this->getConfig('secret');
        $signatureValue = hash_hmac('sha1', $expiryTime . ':' . $secret, $secret);
        $nonceValue = $expiryTime . ':' . $signatureValue;

        return base64_encode($nonceValue);
    }