You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: password_credentials.go
    path of file: ./repos/infra/internal/server/authn
    
    the code of the file until where you have to start completion: package authn

import (
	"context"
	"fmt"
	"time"

	"golang.org/x/crypto/bcrypt"

	"github.com/infrahq/infra/internal/server/data"
)

// passwordCredentialAuthn allows presenting username/password credentials in exchange for an access key
type passwordCredentialAuthn struct {
	Username string
	Password string
}

func NewPasswordCredentialAuthentication(username, password string) LoginMethod {
	return &passwordCredentialAuthn{
		Username: username,
		Password: pass
    
func (a *passwordCredentialAuthn) Authenticate(ctx context.Context, db *data.Transaction, requestedExpiry time.Time) (AuthenticatedIdentity, error) {
	if a.Username == "" {
		return AuthenticatedIdentity{}, fmt.Errorf("username required for password authentication")
	}
	identity, err := data.GetIdentity(db, data.GetIdentityOptions{ByName: a.Username})
	if err != nil {
		return AuthenticatedIdentity{}, fmt.Errorf("could not get identity for username: %w", err)
	}

	// Infra users can have only one username/password combo, look it up
	userCredential, err := data.GetCredentialByUserID(db, identity.ID)
	if err != nil {
		return AuthenticatedIdentity{}, fmt.Errorf("validate creds get user: %w", err)
	}

	// compare the stored hash of the user's password and the hash of the presented password
	err = bcrypt.CompareHashAndPassword(userCredential.PasswordHash, []byte(a.Password))
	if err != nil {
		// this probably means the password was wrong
		return AuthenticatedIdentity{}, fmt.Errorf("could not verify password: %w", err)
	}

	authnIdentity := AuthenticatedIdentity{
		Identity:      identity,
		Provider:      data.InfraProvider(db),
		SessionExpiry: requestedExpiry,
	}

	if userCredential.OneTimePassword {
		// scope the login down to Password Reset Only
		authnIdentity.AuthScope.PasswordResetOnly = true
		authnIdentity.CredentialUpdateRequired = true
	}

	// authentication was a success
	return authnIdentity, nil // password login is always for infra users
}