Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <windows.h>
- using namespace std;
- class PasswordInput
- {
- private:
- string password; /* The string to store the password */
- public:
- /* string passed to it will be the actual password */
- PasswordInput(string pass) : password(pass) { }
- void Input() /* Get the password from the user */
- {
- string input; /* The string to store the input */
- while (true) /* Infinite loop until RETURN is pressed */
- {
- char temp;
- temp = getch(); /* wait for user input a character */
- /* check if it return was pressed, if so exit the loop */
- if (GetAsyncKeyState(VK_RETURN))
- break;
- input += temp;
- cout << '*';
- }
- if (password==input) /* If they match, user could gain access to something */
- cout << "\nThat's correct!";
- else /* Otherwise, tell them it's wrong */
- cout << "\nThat's wrong!";
- }
- };
- int main()
- {
- PasswordInput pass("passme");
- pass.Input(); /* Get the input from the user and compare if it's the password */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement