Skip to content
Browse files

Initial commit, sources and binary file included

  • Loading branch information...
0 parents commit b898988c86aa096db0edfb2bc671ab2c792562ba @Seldaek committed Aug 26, 2012
Showing with 120 additions and 0 deletions.
  1. +44 −0 README.md
  2. BIN build/hiddeninput.exe
  3. +21 −0 src/hiddeninput.c
  4. +24 −0 src/hiddeninput.cpp
  5. +31 −0 src/version.rc
44 README.md
@@ -0,0 +1,44 @@
+Hidden Input
+------------
+
+Executing this program allows to prompt users in interactive
+CLI apps for passwords without it being printed in the terminal.
+
+This should be easier, but it's unfortunately not possible to
+achieve with most higher level languages that do not offer
+an abstraction for it. Therefore instead of relying on popular
+cheap tricks using VBScript to fire up a prompt (which was never
+even working well since the password is shown in clear while
+the user types it in) I decided to build this from C++ sources
+I found on [stackoverflow](http://stackoverflow.com/questions/6899025/hide-user-input-on-password-prompt).
+Credits go to [guestgulkan](http://www.cplusplus.com/user/E6M4jE8b/)
+from cplusplus.com, whoever (s)he may be.
+
+Usage
+-----
+
+Get the build/hiddeninput.exe file into your project and execute it
+to accept user input. Whatever the user types until a newline will
+be output back to the caller but will not show up in the terminal.
+
+C++
+---
+
+hiddeninput.cpp is the original sources modified so that it compiles
+with VC2008 which allows the executable to run fine from Win XP onwards.
+
+C
+-
+
+hiddeninput.c is an alternative version I worked on using the ancestral
+[conio](http://en.wikipedia.org/wiki/Conio.h) utilities. It is not
+completely functionally equivalent to the C++ version so I chose not to
+include the binary in the repo. Should you really have adverse reactions
+to running compiled C++ code, you can easily build this one yourself instead.
+
+License
+-------
+
+This is in the public domain as far as I am concerned. Should anyone involved
+in writing the original bits feel particularly sad or offended by my publishing
+of the sources or binary, drop me a line.
BIN build/hiddeninput.exe
Binary file not shown.
21 src/hiddeninput.c
@@ -0,0 +1,21 @@
+#include "stdio.h"
+#include "stdlib.h"
+#include "conio.h"
+
+int main(void) {
+ int input;
+
+ char text[255] = "";
+ int ptr = 0;
+
+ while (++ptr < 255) {
+ input = _getch();
+ if (input == 13 || input == 10) {
+ break;
+ }
+ sprintf(text, "%s%c", text, input);
+ }
+
+ printf("%s", text);
+ return 0;
+}
24 src/hiddeninput.cpp
@@ -0,0 +1,24 @@
+#define _WIN32_WINNT 0x0500
+#define WINVER 0x0500
+#define WIN32_LEAN_AND_MEAN
+#define NTDDI_VERSION 0x05000000
+
+#include <iostream>
+#include <string>
+#include <windows.h>
+
+using namespace std;
+
+int main()
+{
+ HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
+ DWORD mode = 0;
+ GetConsoleMode(hStdin, &mode);
+ SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT));
+
+ string s;
+ getline(cin, s);
+
+ cout << s << endl;
+ return 0;
+}
31 src/version.rc
@@ -0,0 +1,31 @@
+1 VERSIONINFO
+ FILEVERSION 1,0,0,0
+ PRODUCTVERSION 1,0,0,0
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "FileDescription", "Reads from stdin without leaking info to the terminal and outputs back to stdout"
+ VALUE "FileVersion", "1, 0, 0, 0"
+ VALUE "InternalName", "hiddeninput"
+ VALUE "LegalCopyright", "Jordi Boggiano - 2012"
+ VALUE "OriginalFilename", "hiddeninput.exe"
+ VALUE "ProductName", "Hidden Input"
+ VALUE "ProductVersion", "1, 0, 0, 0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END

0 comments on commit b898988

Please sign in to comment.
Something went wrong with that request. Please try again.