emscripten-core / emscripten-core/emscripten

Password input with no echo is not working

Open
#21,731 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Hi,
I am trying to compile the simple program below which works fine with gcc but does not work with emcc.
The objective is to input a password with no echo on terminal for security reasons.
When compiled with emcc, getchar() is not blocking for user input, always leading to an empty password.
Is there any way to make this work with emscripten? (maybe with another method?)
Thanks a lot for your help and feedback.
Kind regards,
Maurice

**Failing command lines in full:**
emcc pass.c -o pass.js

Same question with:
emcc -lnodefs.js -lnoderawfs.js pass.c -o pass.js

```cpp
#include
#include
#include

#define SIZE 100

void getPassword(char password[]) {
static struct termios oldt, newt;
int i = 0;
int c;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
while ((c = getchar())!= '\n' && c != EOF && i < SIZE) {
password[i++] = c;
}
password[i] = '\0';
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
}

int main(void) {
char password[SIZE];
printf("Password: ");
getPassword(password);
printf("\nPassword = <%s>\n", password);
return 0;
}
```

**Version of emscripten/emsdk:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.53 (ce5114bdd2175c7297583d3c25a53ca95d22f4ce)
clang version 19.0.0git (https://github.com/llvm/llvm-project febb4c42b192ed7c88c17f91cb903a59acf20baf)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.