Why does my code return: error could not read from stdin
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#define MAXLINE 256

#define SUCCESS "Password verified\n"
#define INVALID "Invalid password\n"
#define NO_USER "No such user\n"

int main(void) {
    char user_id[MAXLINE];
    char password[MAXLINE];

    if (fgets(user_id, MAXLINE, stdin) == NULL) {
        perror("fgets");
        exit(1);
    }
    if (fgets(password, MAXLINE, stdin) == NULL) {
        perror("fgets");
        exit(1);
    }

    user_id[31] = '\0';
    password[9] = '\0';

    int pipefd[2];
    int a = pipe(pipefd);
    if (a < 0) {
        perror("pipe");
        exit(1);
    }
    int n = fork();
    if (n < 0) {
        perror("fork");
        exit(1);
    } else if (n == 0) {
        close(pipefd[1]);
        dup2(pipefd[0], STDIN_FILENO);
        int n = execl("./validate", "validate", NULL);
        if (n < 0) {
            perror("execl");
            exit(1);
        }
    } else {
        close(pipefd[0]);
        write(pipefd[1], user_id, sizeof(user_id));
        write(pipefd[1], password, sizeof(password));
        close(pipefd[1]);

        int status;
        wait(&status);

        if (WIFEXITED(status)) {
            int n = WEXITSTATUS(status);
            if (n == 0) {
                printf(SUCCESS);
            } else if (n == 2) {
                printf(INVALID);
            } else if (n == 3) {
                printf(NO_USER);
            } else {
                printf("Error");
                return -1;
            }
        }
    }

    return 0;
}
