simon-hofmann.org

Welcome to my mind.
Watch your step, it's a bit messy around here!

Passwords, please!

• D and Programming

A small project of mine requires the user to enter a password.

Since it’s not that cool to visibly enter any password, I was looking for a solution to hide the terminal output while entering the password.

A quick solution to this problem is shown below using a small snippet of D code.

Example:

import std.process;
import std.stdio;
import std.string;

int main()
{
    string password;
    executeShell("stty -echo");
    password = chomp(readln());
    executeShell("stty echo");
    
    writeln("Password: ", password);

    return 0;
}

It can also be found in my useful_things repo on GitHub

Have fun!