false positive

in line 120 when im looking to see if i press enter it always thinks i did is this because i pressed enter earlier and how would i be able to fix it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#define _AFXDLL

#include <iostream>
#include <string>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include "stdafx.h" 
#include "easendmailobj.tlh"
 
using namespace EASendMailObjLib;
using namespace std;

int main(int argc, char* argv[])
{
	string create_password;
	string confirm_password;
	string word_password;
	string enter_password;

	_bstr_t x;
	string verification_code;

///////////////making word password//////////////////////////

	while (true)
	{
		cout << "Create password" << endl;
		getline(cin, create_password);
		cout << "Confirm password" << endl;
		getline(cin, confirm_password);

		if (create_password == confirm_password)
		{
			cout << "Passwords match" << endl << "Password set" << endl;
			word_password = create_password;
			Sleep(2000);
			break;
		}
		else
		{
			cout << "Passwords do not match please try again" << endl;
			continue;
		}
	}

///////////random code and email//////////////////////////
	
	while (true)
	{

		::CoInitialize(NULL);

		srand(time(NULL));
		x = rand() % 99999999 + 11111111;

		try
		{
			IMailPtr oSmtp = NULL;
			oSmtp.CreateInstance("EASendMailObj.Mail");
			oSmtp->LicenseCode = ("TryIt");

			// Set your gmail email address
			oSmtp->FromAddr = ("gmailid@gmail.com");

			// Add recipient email address
			oSmtp->AddRecipientEx(("gmailid@gmail.com"), 0);

			// Set email subject
			oSmtp->Subject = ("verification pin");

			// Set email body
			oSmtp->BodyText = (x);

			// Gmail SMTP server address
			oSmtp->ServerAddr = ("smtp.gmail.com");

			// If you want to use direct SSL 465 port,
			// Please add this line, otherwise TLS will be used.
			// oSmtp->ServerPort = 465;

			// detect SSL/TLS automatically
			oSmtp->SSL_init();

			// Gmail user authentication should use your
			// Gmail email address as the user name.
			// For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com"
			oSmtp->UserName = ("gmailid@gmail.com");
			oSmtp->Password = ("password");

			printf("Sending verification code to your email ...\r\n");

			if (oSmtp->SendMail() == 0)
			{
				printf(("New verification code was made!\r\n"));
			}
			else
			{
				printf(("failed to send email with the following error: %s\r\n"),
					(const TCHAR*)oSmtp->GetLastErrDescription());
			}

			if (oSmtp != NULL)
				oSmtp.Release();
		}

		catch (_com_error &ep)
		{
			printf(("Error: %s"), (const TCHAR*)ep.Description());
		}


		///////////////unlocking computer//////////////////////////

		while (true)
		{
			cout << "press enter to unlock" << endl;
			Sleep(2000);

			if (GetAsyncKeyState(VK_RETURN))
			{
				Sleep(2000);
				cout << "Enter password: ";
				getline(cin, enter_password);

				if (enter_password == word_password)
				{
					cout << "Password is correct" << endl;

					cout << "Enter Verification code: ";
					getline(std::cin, verification_code);
					const _bstr_t bstr_verification_code(verification_code.c_str());

					if (bstr_verification_code == x)
					{
						cout << "Verification is correct" << endl;
						return 0;
					}
					else
					{
						cout << "Verification is incorrect" << endl;
						break;
					}
				}
				else
				{
					cout << "Password is Incorrect" << endl;
					break;
				}
			}
			else
			{
				break;
			}
			break;
		}
		cout << "creating new varification key" << endl;
		continue;

	}

	return 0;
}
closed account (jh5jz8AR)
Hey Kmtompkins,

I am learning C++as we speak so forgive me if I am wrong as this is just an idea.

What if you put cin.clear() right before hand. If I am not mistaken you are correct about it reading your previous returns. So if you cleared cin, it would not have any previous returns in there.

If I am wrong, please correct me so I know.
From http://msdn.microsoft.com/en-us/library/windows/desktop/ms646293%28v=vs.85%29.aspx:
If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState.

I think you want to look at the most significant bit only.
yes that does sound like what i want but i cant open your link
Just remove the : at the end of the link - the page will open.
Topic archived. No new replies allowed.