Skip to content

Commit b898988

Browse files
committed
Initial commit, sources and binary file included
0 parents  commit b898988

File tree

5 files changed

+120
-0
lines changed

5 files changed

+120
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Hidden Input
2+
------------
3+
4+
Executing this program allows to prompt users in interactive
5+
CLI apps for passwords without it being printed in the terminal.
6+
7+
This should be easier, but it's unfortunately not possible to
8+
achieve with most higher level languages that do not offer
9+
an abstraction for it. Therefore instead of relying on popular
10+
cheap tricks using VBScript to fire up a prompt (which was never
11+
even working well since the password is shown in clear while
12+
the user types it in) I decided to build this from C++ sources
13+
I found on [stackoverflow](http://stackoverflow.com/questions/6899025/hide-user-input-on-password-prompt).
14+
Credits go to [guestgulkan](http://www.cplusplus.com/user/E6M4jE8b/)
15+
from cplusplus.com, whoever (s)he may be.
16+
17+
Usage
18+
-----
19+
20+
Get the build/hiddeninput.exe file into your project and execute it
21+
to accept user input. Whatever the user types until a newline will
22+
be output back to the caller but will not show up in the terminal.
23+
24+
C++
25+
---
26+
27+
hiddeninput.cpp is the original sources modified so that it compiles
28+
with VC2008 which allows the executable to run fine from Win XP onwards.
29+
30+
C
31+
-
32+
33+
hiddeninput.c is an alternative version I worked on using the ancestral
34+
[conio](http://en.wikipedia.org/wiki/Conio.h) utilities. It is not
35+
completely functionally equivalent to the C++ version so I chose not to
36+
include the binary in the repo. Should you really have adverse reactions
37+
to running compiled C++ code, you can easily build this one yourself instead.
38+
39+
License
40+
-------
41+
42+
This is in the public domain as far as I am concerned. Should anyone involved
43+
in writing the original bits feel particularly sad or offended by my publishing
44+
of the sources or binary, drop me a line.

build/hiddeninput.exe

9 KB
Binary file not shown.

src/hiddeninput.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "stdio.h"
2+
#include "stdlib.h"
3+
#include "conio.h"
4+
5+
int main(void) {
6+
int input;
7+
8+
char text[255] = "";
9+
int ptr = 0;
10+
11+
while (++ptr < 255) {
12+
input = _getch();
13+
if (input == 13 || input == 10) {
14+
break;
15+
}
16+
sprintf(text, "%s%c", text, input);
17+
}
18+
19+
printf("%s", text);
20+
return 0;
21+
}

src/hiddeninput.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#define _WIN32_WINNT 0x0500
2+
#define WINVER 0x0500
3+
#define WIN32_LEAN_AND_MEAN
4+
#define NTDDI_VERSION 0x05000000
5+
6+
#include <iostream>
7+
#include <string>
8+
#include <windows.h>
9+
10+
using namespace std;
11+
12+
int main()
13+
{
14+
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
15+
DWORD mode = 0;
16+
GetConsoleMode(hStdin, &mode);
17+
SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT));
18+
19+
string s;
20+
getline(cin, s);
21+
22+
cout << s << endl;
23+
return 0;
24+
}

src/version.rc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
1 VERSIONINFO
2+
FILEVERSION 1,0,0,0
3+
PRODUCTVERSION 1,0,0,0
4+
FILEFLAGSMASK 0x17L
5+
#ifdef _DEBUG
6+
FILEFLAGS 0x1L
7+
#else
8+
FILEFLAGS 0x0L
9+
#endif
10+
FILEOS 0x4L
11+
FILETYPE 0x1L
12+
FILESUBTYPE 0x0L
13+
BEGIN
14+
BLOCK "StringFileInfo"
15+
BEGIN
16+
BLOCK "040904b0"
17+
BEGIN
18+
VALUE "FileDescription", "Reads from stdin without leaking info to the terminal and outputs back to stdout"
19+
VALUE "FileVersion", "1, 0, 0, 0"
20+
VALUE "InternalName", "hiddeninput"
21+
VALUE "LegalCopyright", "Jordi Boggiano - 2012"
22+
VALUE "OriginalFilename", "hiddeninput.exe"
23+
VALUE "ProductName", "Hidden Input"
24+
VALUE "ProductVersion", "1, 0, 0, 0"
25+
END
26+
END
27+
BLOCK "VarFileInfo"
28+
BEGIN
29+
VALUE "Translation", 0x409, 1200
30+
END
31+
END

0 commit comments

Comments
 (0)