Need some help accessing password string / Debugging
- by Josh Lake
I'm doing this code for the sole purpose in trying out how to get the password field masked. Any suggestions on where to go next?
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <cstring>
#include <conio.h>
using namespace std;
inline void keep_window_open() { char ch; cin>>ch; }
int main()
{
cout << "Welcome to the Classified Network, DOD842349729961971\n";
cout << "Username: \n";
string admin = "gardinerca";
string root_password = "password1";
string full_name = "User Name";
string name;
cin >> name;
if (name == admin)
{
printf("Password: ");
char password[10];
int i;
for (i = 0; i <= 10; i++)
{
int c = getch();
if (c == '\n' || c == EOF)
break;
password[i] = c;
printf("*");
}
password[i] = '\0';
if (strcmp(password, root_password) == 0)
{
system("CLS");
cout << "Welcome " << full_name << " to the Classified Network\n";
cout << "Would you like to play a game? (Y or N)\n";
string play_game;
cin >> play_game;
if (play_game == "Y")
{
cout << "How many balls can you stick in your mouth?\n";
int balls;
cin >> balls;
string one;
string two;
one = "One Ball";
two = "Two Ball's";
if (balls == 1)
cout << "You can honestly stick " << one << " in your mouth?";
}
else
{
cout << "You have selected the No Option. Thats fine...we don't want to play with you either\n";
}
}
else
{
cout << "Invaild Password. Please contact system administrator.\n";
cin.clear();
system ("PAUSE");
}
else
{
cout << "No Username found. Please contact system administrator.\n";
cin.clear();
system ("PAUSE");
}
return 0;
}