My own suggestion is -- DO NOT DO IT!
Don't reinvent the wheel, use a password helper if you want 'stars'
Instead do something like the following pseudo-code... If the TTY_ASSPASS environment variable is set -- call that password helper. There are a number available, including "systemd-ask-password" If there is a TTY - fall back to read no echo (getpass.getpass()) If there is no TTY, - fall back just read STDIN with rstrip()
This not only lets the user select a password input program (via an environment variable (or some other confuguration), but also lets them substitute for other sources of passwords, like GUI input, or collecting password from a pre-opened keyring password daemon, or elsewhere
Don't restrict or otherwise limit where passwords come from!
For notes on password helpers see.. https://antofthy.gitlab.io/info/crypto/passwd_input.txt
For a shell script password helper https://antofthy.gitlab.io/software/#askpass_stars
Looks like Andrei Krivoshei answer has already made a start on that, resulting in something very similar, but still in its infancy.