I'm currently having an issue with replacing a user input without them pressing the "return/enter" key on their keyboard. This is to allow for entering passwords without them directly showing in a terminal window.
Example for the code below, when using telnet to connect to the tcp server, I'm expecting the console to log every each key the user presses and so whenever the user inputs a key, I am able to refresh the console and replace the key with a *
, or even for the users chat input to not show in their terminal(only viewable when I print it out).
By receiving user input via character mode, this would allow my server to acknowledge when the user sends in an input.
The issue with the code below is that the socket.on('data')
only receives data when the user presses the return/enter
key.
Here's a minimal reproducible snippet:
const Net = require('net');
var server = Net.Server()
server.on('connection', async(socket) => {
socket.on('data', async data => {
console.log(data)
});
socket.write('Password: ')
})
server.listen(3000, function() {
console.log('server is listening in 127.0.0.1:3000');
});
I've had some possible solutions(and solutions that I have tried) which may help the community in answering my question:
• Doing MODE CHARACTER
in telnet, this isn't really what I was looking for.
• Some form of a function allows for user input but disables the client side from displaying the string in the terminal window and replaces the user inputs with *
.
• Some form of a function which allows the server to acknowledge when there is a change in the string that the user as entered and clearing the terminal window, while replacing the user string with *
.
• Completely disabling the user interface in showing the users input and only allowing the server side to view the inputted string(this wouldn't allow the user to see the length of their password).