async Task AuthenticateCleartext(bool async, CancellationToken cancellationToken) { var passwd = Settings.Password; if (passwd == null) { // No password was provided. Attempt to pull the password from the pgpass file. var matchingEntry = PgPassFile.LoadDefaultFile()?.GetFirstMatchingEntry(Settings.Host, Settings.Port, Settings.Database, Settings.Username); if (matchingEntry != null) { Log.UsingPgpassFile(); 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, cancellationToken); await WriteBuffer.Flush(async); await ReadExpecting <AuthenticationRequestMessage>(async); }
async Task AuthenticateMD5(string username, byte[] salt, 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 MD5)"); } await PasswordMessage .CreateMD5(passwd, username, salt) .Write(WriteBuffer, async); await WriteBuffer.Flush(async); await ReadExpecting <AuthenticationRequestMessage>(async); }
public void TestPasswordMessageCreateMd5() { var salt = new byte[] { 0x77, 0x16, 0x3e, 0xe3 }; var authMessage = new AuthenticationMessage { AuthenticationMessageType = AuthenticationMessageType.MD5Password, DataBuffer = salt }; var state = PostgresClientState.CreateDefault(); var connectionString = new PostgresConnectionString( PostgresServerInformation.FakeConnectionString); var passwordMessage = PasswordMessage .CreateMd5(authMessage, state, connectionString); const string expectedHash = "md583ce447ce89d7e4e943205ff8f82f76a"; try { var actualHash = Encoding.ASCII.GetString( passwordMessage.Password, 0, passwordMessage.PasswordLength); Assert.AreEqual(0x23, passwordMessage.PasswordLength); Assert.AreEqual(expectedHash, actualHash); } finally { authMessage.TryDispose(); passwordMessage.TryDispose(); } }
private void LoginPassword_PasswordChanged(object sender, RoutedEventArgs e) { //var dvm = SimpleIoc.Default.GetInstance<LoginViewModel>() var pm = new PasswordMessage { Password = ((PasswordBox)sender).Password }; Messenger.Default.Send <PasswordMessage>(pm); }
private void PasswordMessageHandler(INetworkConnection conn, PasswordMessage msg) { if (msg.password == authPassword) { conn.Send(new AcceptPasswordMessage() { allowed = true }); base.OnServerAuthenticate(conn); } }
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); }
async Task AuthenticateMD5(string username, byte[] salt, bool async, CancellationToken cancellationToken) { var passwd = GetPassword(); if (passwd == null) { throw new NpgsqlException("No password has been provided but the backend requires one (in MD5)"); } await PasswordMessage .CreateMD5(passwd, username, salt) .Write(WriteBuffer, async, cancellationToken); await WriteBuffer.Flush(async); await ReadExpecting <AuthenticationRequestMessage>(async); }
private void Authenticate(AuthenticationMessage authenticationMessage) { PasswordMessage passwordMessage; switch (authenticationMessage.AuthenticationMessageType) { case AuthenticationMessageType.MD5Password: passwordMessage = PasswordMessage.CreateMd5( authenticationMessage, ClientState, PostgresConnectionString); break; default: throw new ArgumentOutOfRangeException( nameof(authenticationMessage.AuthenticationMessageType), authenticationMessage.AuthenticationMessageType, "Authentication method not supported."); } using (passwordMessage) { WriteMessage(passwordMessage); } }
private void HandlePasswordMessage(PasswordMessage msg) { this.Password = msg.Password; }
internal GSSPasswordMessageStream(NpgsqlConnector connector) { _connector = connector; _msg = new PasswordMessage(); }