Supress character echo in TCPStream

I have a little snippet of code below where I'm asking a user to input a password, and I want to supress the characters they are typing from displaying. (This isn't a high-security app, just a little toy application I'm writing to learn). I would appreciate any suggestions.

fn handle_login(mut stream: TcpStream, command: &str, argument: &str) {
    let pwprompt = "Please enter your password: ";
    stream.write(pwprompt.as_bytes()).unwrap();
    stream.flush().unwrap();
    let mut buffer = [0; 1024];
    stream.read(&mut buffer).unwrap();
    let mut user_password = String::from_utf8_lossy(&mut buffer); 

In a TCP stream?

Yes. I've made a basic server and I'm connecting to it via Telnet. I edited the code snipped because I had forgotten to include the fn arguments.

Telnet supports something called IAC commands. You should send the appropriate IAC command and hope that whatever telnet client the user is using supports it. See e.g. this answer for an IAC command you might want to try.

Thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.