13 Replies - 1450 Views - Last Post: 25 January 2009 - 10:21 PM Rate Topic: -----

#1 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Secure Password Entry

Posted 25 January 2009 - 05:52 PM

I am a bit confused on how I'm going to input the example script for secure password entry (found here ) with my script. I want the users to enter the password but then they be able to type without it typing in getch.

if (strcmp(awnser, "decode")== 0){
					   system("CLS");
					   cout << "Processing.";
					   Sleep(1000);
					   cout << ".";
					   Sleep(1000);
					   cout << "." << endl << endl;
					   cout << "Enter your name: ";
					   cin >> name;
					   if (strcmp(name, "Blade")== 0){
										  cout << "AUTHORIZATION CODE: ";
										  cin >> password;
										  if (strcmp(password, "password")== 0){
															 system("CLS");
															 cout << "Welcome Blade" << endl;
															 cout << "NOW ACCESSING Blank" << endl;
															 Sleep(1000);
															 cin >> awnser;
															 if (strcmp(awnser, "Command")== 0){
																			  system("CLS");
																			  {
																							keybd_event(VK_MENU,0x38,0,0); //Press down Alt
																							keybd_event(VK_RETURN,0x1c,0,0); //Press down Enter
				  
																							keybd_event(VK_MENU,0x38,KEYEVENTF_KEYUP,0); //Release Alternate
																							keybd_event(VK_RETURN,0x1c,KEYEVENTF_KEYUP,0);
																							}
																							cin >> awnser;
																							if (strcmp(awnser, "258963")== 0){
																											   {
																														   keybd_event(VK_MENU,0x38,0,0); //Press down Alt
																														   keybd_event(VK_RETURN,0x1c,0,0); //Press down Enter
				  
																														   keybd_event(VK_MENU,0x38,KEYEVENTF_KEYUP,0); //Release Alternate
																														   keybd_event(VK_RETURN,0x1c,KEYEVENTF_KEYUP,0);
																														   }
																														   goto Main;
																											 }else{
																												   system("CLS");
																												   cout << "That is incorrect" << endl;
																												   BlockInput(true);
																												   Sleep(1400);
																												   BlockInput(false);
																												   return 0;
																												   }
																							}
															 }
										  }
					   }else{
							 system("CLS");
							 return 0;
							 }




Notice this is only one part of my script.

This post has been edited by Blade2021: 25 January 2009 - 05:53 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Secure Password Entry

#2 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Secure Password Entry

Posted 25 January 2009 - 06:57 PM

If you want it to be "secure," I assume you're using a command console.
You could always turn the foreground/background to black when the user types their password in.

You could also have it not echo what they type (so it isn't visually displayed).

FYI, you're "supposed to use SendInput instead of keybd_event" now.
Was This Post Helpful? 0
  • +
  • -

#3 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Re: Secure Password Entry

Posted 25 January 2009 - 07:03 PM

SendInput? Never was told that and can you go in more detail on how to get it not to echo? (with also instructions on how to turn the echo back on)


EDIT: Ok, did a bit of research on Echo off and on and inputed it into my program but it doesn't work ;)

This post has been edited by Blade2021: 25 January 2009 - 09:05 PM

Was This Post Helpful? 0
  • +
  • -

#4 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Secure Password Entry

Posted 25 January 2009 - 09:18 PM

I'm not refering to the system call ("echo off") on M$. There's an actual buffer for text when you type, and you can have it "eat" the bytes, so they don't show. Here's a link to the MSDN to show what I'm refering to:
- http://msdn.microsof...147(VS.85).aspx
- http://msdn.microsof...961(VS.85).aspx
I had a very long and hard time figuring it out, because there isn't alot of clear references in books or internet resources, it's sort of like unspecificed arguments in a function, rather hard to find info. on it.

At anyrate, here's a quick reference to what I mean about SendInput (I'll provide an example program to better show one method of using it):
- http://msdn.microsof...y/ms646310.aspx

#include <windows.h>
#include <winable.h>

using namespace std;

HWND hWnd = FindWindow(0, "Diablo II");

void SendKey(BYTE vKey) {
INPUT Input;
ZeroMemory(&Input, sizeof(Input)); // Sets all members to 0
Input.type = INPUT_KEYBOARD; // keybd_event
Input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
Input.ki.wVk = vKey; // Virtual Key
SendInput(1, &Input, sizeof(INPUT));

return;
}

int main() {

    if (!FindWindow(0, "Diablo II")) {
                       MessageBox(0, "Diablo II's Window not found", " ", 0);
                       return 0;
    }

    SetForegroundWindow(hWnd);
    Sleep(500);

    SendKey((UCHAR)VkKeyScan('S'));
    SendKey((UCHAR)VkKeyScan('a'));
    SendKey((UCHAR)VkKeyScan('y'));
    return 0;
}


As you can clearly see from the example, it's attempting to find the window "Diablo II," which is a Blizzard game. You could make it work for anything (you can use the windows title or another method, you can even use the PID of the program to reference it).
Was This Post Helpful? 0
  • +
  • -

#5 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Re: Secure Password Entry

Posted 25 January 2009 - 09:38 PM

hmm I'll have to do more research about the virtual keyboard issue but back to the echo deal. Can you give an example of the code that would be used. MsDn can be very confusing without examples.
Was This Post Helpful? 0
  • +
  • -

#6 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Secure Password Entry

Posted 25 January 2009 - 09:40 PM

Yes, yes MSDN can be very confusing without examples. I'll go find a program I used it in, moment.

OK, no luck. Here's a brief idea of it in action:
    HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);
    FlushConsoleInputBuffer(hConsole);


That about sums it up.

EDIT:
#include <iostream>
#include <windows.h>
using namespace std;

int DoNotShowText() {

	HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);
	FlushConsoleInputBuffer(hConsole);

	cout << "K key detected";

	return 0;
}

int main() {

	cout << "Hello, people! Press the K key now!\n";

	while (!GetAsyncKeyState(0x4B)) { }

	DoNotShowText();

	cin.get();
	return 0;
}


You can also use the ReadConsoleInput to remove what they type, I'll demonstrate that in a moment.

This post has been edited by Hyper: 25 January 2009 - 09:48 PM

Was This Post Helpful? 0
  • +
  • -

#7 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Re: Secure Password Entry

Posted 25 January 2009 - 09:48 PM

hmm... Still having alot of trouble with such a simple thing. I hate walking away but damn this is confusing.
Was This Post Helpful? 0
  • +
  • -

#8 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Secure Password Entry

Posted 25 January 2009 - 09:48 PM

No need to walk away.
Was This Post Helpful? 0
  • +
  • -

#9 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Re: Secure Password Entry

Posted 25 January 2009 - 09:51 PM

I don't think I understand what is going on. I inputed it to experiment with it and it still isn't doing what I believe it should. Not to mention the errors that came when I messed with it. Can you clarify more on whats going on or post an example of it IN a password script so I can see where it should be inputed.
Was This Post Helpful? 0
  • +
  • -

#10 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Secure Password Entry

Posted 25 January 2009 - 09:58 PM

Here's a bit of humor (as you type it, say it outloud to get a good kick):

#include <iostream>
#include <windows.h>
using namespace std;

int DoNotShowText() {

    HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);
    FlushConsoleInputBuffer(hConsole);

    cout << "K key detected\n";

    return 0;
}

int main() {

    HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);
    DWORD numEvents = 0;
    DWORD numEventsRead = 0;

    cout << "Hello, people! For demonstration purposes, please type the following:\n\n"
         << "I am not a fig plucker, not a fig plucker son\n"
         << "But I'll pluck figs 'til the fig pluckers come!\n\n";

    while (true) {
        GetNumberOfConsoleInputEvents(hConsole, &numEvents);
        if (numEvents != 0) {
            INPUT_RECORD *eventBuffer = new INPUT_RECORD[numEvents];
            ReadConsoleInput(hConsole, eventBuffer, numEvents, &numEventsRead);

            for (int x = 0; x < numEventsRead; ++x) {
                if (eventBuffer[x].EventType == KEY_EVENT) {
                    if (eventBuffer[x].Event.KeyEvent.uChar.AsciiChar == 'k') {
                        DoNotShowText();
                    }
                }
            }
        }
    }

    cin.get();
    return 0;
}


View PostBlade2021, on 25 Jan, 2009 - 08:51 PM, said:

I don't think I understand what is going on. I inputed it to experiment with it and it still isn't doing what I believe it should. Not to mention the errors that came when I messed with it. Can you clarify more on whats going on or post an example of it IN a password script so I can see where it should be inputed.


1) You have to include: windows.h
2) You have to be running the M$ operating system
3) What it's doing is flushing out the buffer. When you type a key, it gets sent to the buffer hundreds if not thousands of times for every millisecond you have the key pressed down (even for a split moment). Those key inputs stay in the buffer until you explicity remove (or "flush") them out.

For example, if you do this:
char Test;
cout << "Input any two letters then hit enter: ";
cin >> Test;

cout << "Input another letter: ";
cin >> Test2;


The characters in the buffer will go from the first cin into the second cin. You can explicity flush those using _flushall() or other similar calls.

There's another kind of buffer, one that deals with the keyboard directly. If you're using GetAsyncKeyState for instance, or GetKeyState, GetKeyboardState, etc. Then FlushConsoleInputBuffer is a prime call to use.
Was This Post Helpful? 0
  • +
  • -

#11 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Re: Secure Password Entry

Posted 25 January 2009 - 10:03 PM

That helped explain alot, thanks.
Was This Post Helpful? 0
  • +
  • -

#12 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Secure Password Entry

Posted 25 January 2009 - 10:07 PM

View PostBlade2021, on 25 Jan, 2009 - 09:03 PM, said:

That helped explain alot, thanks.


You're very welcome, don't forget to click the green button!
Was This Post Helpful? 0
  • +
  • -

#13 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Re: Secure Password Entry

Posted 25 January 2009 - 10:11 PM

Green button? and only one thing, how do you get it to accept what the user inputs.
Was This Post Helpful? 0
  • +
  • -

#14 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Secure Password Entry

Posted 25 January 2009 - 10:21 PM

View PostBlade2021, on 25 Jan, 2009 - 09:11 PM, said:

Green button? and only one thing, how do you get it to accept what the user inputs.


"This Post Was Helpful!" that green button! :)

How do you get it to "accept?" Well, that's for you to decide how to go about.
I've merely shown you how to irradicate of what you type being put on the screen.
ReadConsoleInput alone is what removes what the user types. Here's a routine I used it in:

            DWORD NumEvents = 0, NumEventsRead = 0;
            HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);

            while (true) {
                GetNumberOfConsoleInputEvents(hConsole, &NumEvents);

                if (NumEvents != 0) {

                    INPUT_RECORD *eventBuffer = new INPUT_RECORD[NumEvents];
                    ReadConsoleInput(hConsole, eventBuffer, NumEvents, &NumEventsRead);

                    if (GetAsyncKeyState(VK_UP) && Y + 3 < Arrow) {
                        PlaceText(BLACK, "  ", X + 3, Arrow);
                        PlaceText(WHITE, "->", X + 3, Arrow -= 1);
                    }

                    if (GetAsyncKeyState(VK_DOWN) && Arrow < MaxItems) {
                        PlaceText(BLACK, "  ", X + 3, Arrow);
                        PlaceText(WHITE, "->", X + 3, Arrow += 1);
                    }

                    if (GetAsyncKeyState(VK_RETURN)) {
                        CurrItem = Arrow - Y - 3;
                        if (callback(CurrItem, ExitMenu)) { delete eventBuffer; break; }
                    }
                }
            }


Don't mind what you don't understand, merely note where you see it. If the user accidently tries typing "as;jofa;" or anything else of the sort, it won't display a thing! But if they press the directional arrows (numpad or otherwise), it'll move the arrow (->) up or down, depending on which was depressed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1