func (d Dao) Login(ctx context.Context, u User) (*User, error) {
	cols := []string{
		"username",
		"password",
		"points",
	}
	q := db.NewQueryFunction("user_read", cols, u.Username)
	var u2 User
	err := d.db.Query(ctx, q, &u2.Username, &u2.password, &u2.Points)
	if err != nil {
		if errors.Is(err, db.ErrNoRows) {
			return nil, ErrIncorrectLogin
		}
		return nil, fmt.Errorf("reading user: %w", err)
	}
	hashedPassword := []byte(u2.password)
	isCorrect, err := u.isCorrectPassword(hashedPassword)
	switch {
	case err != nil:
		return nil, fmt.Errorf("reading user: %w", err)
	case !isCorrect:
		return nil, ErrIncorrectLogin
	}
	return &u2, nil
}
// Login gets ensures the username/password combination is valid and returns all information about the user.
Login gets ensures the username/password combination is valid and returns all information about the user.
// Login gets ensures the username / password combination is valid and returns all information about the user .
func (d Dao) Login(ctx context.Context, u User) (*User, error) {
	cols := []string{
		"username",
		"password",
		"points",
	}
	q := db.NewQueryFunction("user_read", cols, u.Username)
	var u2 User
	err := d.db.Query(ctx, q, &u2.Username, &u2.password, &u2.Points)
	if err != nil {
		if errors.Is(err, db.ErrNoRows) {
			return nil, ErrIncorrectLogin
		}
		return nil, fmt.Errorf("reading user: %w", err)
	}
	hashedPassword := []byte(u2.password)
	isCorrect, err := u.isCorrectPassword(hashedPassword)
	switch {
	case err != nil:
		return nil, fmt.Errorf("reading user: %w", err)
	case !isCorrect:
		return nil, ErrIncorrectLogin
	}
	return &u2, nil
}
func ( d Dao ) Login ( ctx context . Context , u User ) ( * User , error ) { cols := [ ] string { " " , " " , " " , } q := db . NewQueryFunction ( " " , cols , u . Username ) var u2 User err := d . db . Query ( ctx , q , & u2 . Username , & u2 . password , & u2 . Points ) if err != nil { if errors . Is ( err , db . ErrNoRows ) { return nil , ErrIncorrectLogin } return nil , fmt . Errorf ( " " , err ) } hashedPassword := [ ] byte ( u2 . password ) isCorrect , err := u . isCorrectPassword ( hashedPassword ) switch { case err != nil : return nil , fmt . Errorf ( " " , err ) case ! isCorrect : return nil , ErrIncorrectLogin } return & u2 , nil }
Login gets ensures the username/password combination is valid and returns all information about the user.
Login gets ensures the username / password combination is valid and returns all information about the user .