Esempio n. 1
0
        async Task AuthenticateCleartext(bool async)
        {
            var passwd = Settings.Password;

            // No password was provided. Attempt to pull the password from the pgpass file.
            if (passwd == null)
            {
                var matchingEntry = PgPassFile.Load(Settings.Passfile)?.GetFirstMatchingEntry(Settings.Host, Settings.Port, Settings.Database, Settings.Username);
                if (matchingEntry != null)
                {
                    Log.Trace("Taking password from pgpass file");
                    passwd = matchingEntry.Password;
                }
            }

            if (passwd == null)
            {
                throw new NpgsqlException("No password has been provided but the backend requires one (in cleartext)");
            }

            await PasswordMessage
            .CreateClearText(passwd)
            .Write(WriteBuffer, async);

            await WriteBuffer.Flush(async);

            await ReadExpecting <AuthenticationRequestMessage>(async);
        }
        async Task AuthenticateCleartext(bool async, CancellationToken cancellationToken)
        {
            var passwd = GetPassword();

            if (passwd == null)
            {
                throw new NpgsqlException("No password has been provided but the backend requires one (in cleartext)");
            }

            await PasswordMessage
            .CreateClearText(passwd)
            .Write(WriteBuffer, async, cancellationToken);

            await WriteBuffer.Flush(async);

            await ReadExpecting <AuthenticationRequestMessage>(async);
        }