Skip to content

Commit ae28958

Browse files
committed
Fixed some PostgreSQL authentication method errors and reverted connection-related TrimSuffix back to TrimRight.
1 parent f642416 commit ae28958

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

auth/postgres.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ func (p *PostgresAuthenticator) AuthenticatePlain(username string, password stri
9696
// Encode the hashed text with base64.
9797
encHashedPassword := base64.StdEncoding.EncodeToString(hashedPassword)
9898

99+
// Prepare query for database.
100+
query := fmt.Sprintf("SELECT id FROM users WHERE username = '%s' AND password = '{SHA512}%s'", username, encHashedPassword)
101+
99102
// Query database for user matching all criteria.
100-
err = p.Conn.QueryRow("SELECT id FROM users WHERE username = '$1' AND password = '$2'", username, encHashedPassword).Scan(&dbUserID)
103+
err = p.Conn.QueryRow(query).Scan(&dbUserID)
101104
if err != nil {
102105

103106
// Check what type of error we received.

comm/connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,5 @@ func InternalReceive(reader *bufio.Reader) (string, error) {
155155
return "", err
156156
}
157157

158-
return strings.TrimSuffix(text, "\r\n"), nil
158+
return strings.TrimRight(text, "\r\n"), nil
159159
}

imap/connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (c *Connection) Receive() (string, error) {
8585
return "", err
8686
}
8787

88-
return strings.TrimSuffix(text, "\r\n"), nil
88+
return strings.TrimRight(text, "\r\n"), nil
8989
}
9090

9191
// Send takes in an answer text from server as a

imap/distributor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func InitDistributor(config *config.Config) (*Distributor, error) {
4949
// Open authentication file and read user information.
5050
distr.AuthAdapter, err = auth.NewFileAuthenticator(config.Distributor.AuthFile.File, config.Distributor.AuthFile.Separator)
5151

52-
} else if config.Distributor.AuthAdapter == "Postgres" {
52+
} else if config.Distributor.AuthAdapter == "AuthPostgres" {
5353

5454
// Connect to PostgreSQL database.
5555
distr.AuthAdapter, err = auth.NewPostgresAuthenticator(config.Distributor.AuthPostgres.IP, config.Distributor.AuthPostgres.Port, config.Distributor.AuthPostgres.Database, config.Distributor.AuthPostgres.User, config.Distributor.AuthPostgres.Password, config.Distributor.AuthPostgres.UseTLS)

0 commit comments

Comments
 (0)