@param string $username
@param string $password

@return array
@throws ChallengeException
@throws Exception
176668
public function authenticate($username, $password)
    {
        try {
            $response = $this->client->adminInitiateAuth([
                'AuthFlow' => 'ADMIN_NO_SRP_AUTH',
                'AuthParameters' => [
                    'USERNAME' => $username,
                    'PASSWORD' => $password,
                    'SECRET_HASH' => $this->cognitoSecretHash($username),
                ],
                'ClientId' => $this->appClientId,
                'UserPoolId' => $this->userPoolId,
            ]);

            return $this->handleAuthenticateResponse($response->toArray());
        } catch (CognitoIdentityProviderException $e) {
            throw CognitoResponseException::createFromCognitoException($e);
        }
    }
853777
protected function createUserRecord($username, $password, array $options = [])
    {
        return [
            // Username
            User::FIELD_USERNAME => $username,
            // Password
            User::FIELD_PASSWORD => bcrypt($password),
            // Email
            User::FIELD_EMAIL    => array_key_exists(User::FIELD_EMAIL, $options)
                ? $options[User::FIELD_EMAIL]
                : $username . '@local . com',
            // Home
            User::FIELD_HOME     => array_key_exists(User::FIELD_HOME, $options)
                ? $options[User::FIELD_HOME]
                : null,
            // Is blocked
            User::FIELD_BLOCKED  => array_key_exists(User::FIELD_BLOCKED, $options)
                ? $options[User::FIELD_BLOCKED]
                : false,
            // Is static
            User::FIELD_STATIC   => array_key_exists(User::FIELD_STATIC, $options)
                ? $options[User::FIELD_STATIC]
                : false,
            // Is hidden
            User::FIELD_HIDDEN   => array_key_exists(User::FIELD_HIDDEN, $options)
                ? $options[User::FIELD_HIDDEN]
                : false,
        ];
    }
1369681
public function withCredentials($username, $password)
    {
        if (null === $username || null === $password) {
            // No change if credentials or null
            return $this;
        }

        $new = $this->setValue('username', $username)
            ->setValue('password', $password)
            ->setValue('credentials', [$username, $password]);

        // To keep BC
        $new->username = $username;
        $new->password = $password;
        $new->credentials = [$username, $password];

        return $new;
    }
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;
    }
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;
    }
1334729
public function authenticate(string $username, string $password): ConnectionInterface
    {
        $errorMessage = null;
        $errorNumber  = 0;
        \set_error_handler(static function ($nr, $message) use (&$errorMessage, &$errorNumber) {
            $errorMessage = $message;
            $errorNumber = $nr;
        });

        $resource = \imap_open(
            $this->getServerString(),
            $username,
            $password,
            $this->options,
            $this->retries,
            $this->parameters
        );

        \restore_error_handler();

        if (false === $resource || null !== $errorMessage) {
            throw new AuthenticationFailedException(\sprintf(
                'Authentication failed for user "%s"%s',
                $username,
                null !== $errorMessage ? ': ' . $errorMessage : ''
            ), $errorNumber);
        }

        $check = \imap_check($resource);

        if (false === $check) {
            throw new ResourceCheckFailureException('Resource check failure');
        }

        $mailbox       = $check->Mailbox;
        $connection    = $mailbox;
        $curlyPosition = \strpos($mailbox, '}');
        if (false !== $curlyPosition) {
            $connection = \substr($mailbox, 0, $curlyPosition + 1);
        }

        // These are necessary to get rid of PHP throwing IMAP errors
        \imap_errors();
        \imap_alerts();

        return new Connection(new ImapResource($resource), $connection);
    }
198764
public function authenticate($username, $password)
    {
        $result = $this->getGateway()->authenticate($username, $password);
        $messages = $result->getMessages();

        // all messages beyond the first one are for debugging and
        // not suitable to display to the user.
        foreach ($messages as $i => $message) {
            if ($i > 0) {
                $this->getLogger()->debug(str_replace("\n", "\n  ", $message));
            }
        }

        $message = $messages[0]; // first message is user readable, suitable for showing on login form

        // show better errors than the defaults for various status codes returned by LDAP
        if (!empty($messages[1]) && strpos($messages[1], 'NT_STATUS_ACCOUNT_LOCKED_OUT') !== false) {
            $message = _t(
                __CLASS__ . '.ACCOUNTLOCKEDOUT',
                'Your account has been temporarily locked because of too many failed login attempts. ' .
                'Please try again later.'
            );
        }
        if (!empty($messages[1]) && strpos($messages[1], 'NT_STATUS_LOGON_FAILURE') !== false) {
            $message = _t(
                __CLASS__ . '.INVALIDCREDENTIALS',
                'The provided details don\'t seem to be correct. Please try again.'
            );
        }

        return [
            'success' => $result->getCode() === 1,
            'identity' => $result->getIdentity(),
            'message' => $message,
            'code' => $result->getCode()
        ];
    }
694869
public function basicAuth($username, $password)
    {
        $this->auth = new BasicAuth($username, $password);
        return $this->auth;
    }
830215
public function login(string $username, string $password): void
    {
        $this->fillUsername($username);
        $this->fillPassword($password);
        $this->clickLogin();
    }
373148
public function updatePassword($username, $password)
    {
        /** @var UserInterface|EloquentUser $user */
        if ( ! ($user = $this->sentinel->findByCredentials(['email' => $username]))) {
            return false;
        }

        return $this->sentinel->update($user, ['password' => $password]) instanceof UserInterface;
    }
957807
public static function create(string $username, string $email, string $password) : User
    {
        $user = new User();
        $user->username = $username;
        $user->email    = $email;
        $user->status   = self::STATUS_ACTIVE;
        $user->setPassword($password);
        $user->generateAuthKey();
        return $user;
    }
133692
public function setCredentials($username, $password)
    {
        $this->username = $username;
        $this->password = $password;

        return $this;
    }
277073
public function checkUserCredentials($username, $password)
    {
        $userDetails = $this->getUserDetails($username);

        return $userDetails && $userDetails['password'] && $userDetails['password'] === $password;
    }
67862
protected function getApiResponseAuthToken($username, $password)
    {
        $response = $this->sendRequest('GET', sprintf(
            self::API_AUTH_URL,
            urlencode($username),
            urlencode($password)
        ));

        return $response->getBody()->getContents();
    }
514533
protected function authNtlmResponse( $challenge, $password )
    {
        $password = chunk_split( $password, 1, "\x00" );
        $password = hash( 'md4', $password, true );
        $password .= str_repeat( "\x00", 21 - strlen( $password ) );

        $td = mcrypt_module_open( 'des', '', 'ecb', '' );
        $iv = mcrypt_create_iv( mcrypt_enc_get_iv_size( $td ), MCRYPT_RAND );

        $response = '';        
        for ( $i = 0; $i < 21; $i += 7 )
        {
            $packed = '';
            for ( $p = $i; $p < $i + 7; $p++ )
            {
                $packed .= str_pad( decbin( ord( substr( $password, $p, 1 ) ) ), 8, '0', STR_PAD_LEFT );
            }

            $key = '';
            for ( $p = 0; $p < strlen( $packed ); $p += 7 )
            {
                $s = substr( $packed, $p, 7 );
                $b = $s . ( ( substr_count( $s, '1' ) % 2 ) ? '0' : '1' );
                $key .= chr( bindec( $b ) );
            }

            mcrypt_generic_init( $td, $key, $iv );
            $response .= mcrypt_generic( $td, $challenge );
            mcrypt_generic_deinit( $td );
        }
        mcrypt_module_close( $td );

        return $response;
    }
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);
  }
1165638
public function setAuthCredentials($username, $password)
    {

        $this->setUsername($username);

        $this->setPassword($password);

        $this->authCredentials = base64_encode(
            "{$this->username}:{$this->password}"
        );

    }