Hey guys!
Haven't posted here in ages. Anyway, I have a question about this project I've started. I'm not really sure how to explain what the program actually does, but my question only concerns the first part of the program anyway. (This is the only part I've written so far.)
I'll go right ahead and post the code:
Code:
#include <iostream>
#include <fstream>
#include <conio.h>
using namespace std;
#define nul '\0'
int Initiation;
int Asize;
char Ainput;
string Apassword;
string Apassword2;
////////////////////////////////////////////////////////////////////////////////
// Accounts Structure
////////////////////////////////////////////////////////////////////////////////
struct Accounts
{
string Username;
string Password;
};
////////////////////////////////////////////////////////////////////////////////
// End of Accounts Structure
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Setup function.
////////////////////////////////////////////////////////////////////////////////
bool InitiationFunction()
{
Asize = 0;
Ainput = nul;
Apassword = "";
Apassword2 = "";
cout<<"\n\n\n NEMESIS PROGRAM INITIATED\n\n\n\n Nemesis is currently under maintenance, and some functions may not work\n correctly. Nemesis will be fully operational soon and we apologise for\n any inconvenience this delay may have caused.";
cout<<"\n\n As this is the first time you have executed Nemesis, an administration\n account must be created. The username for this account will be\n automatically set to Nemesis.\n\n Please enter your desired password for this account.\n\n\n\n Desired Password: ";
while ( Ainput != EOF && Ainput != '\n' && Ainput != '\r' )
{
Ainput = getch();
if ( Ainput == '\b' && Asize > 0 )
{
cout<<"\b \b";
Asize--;
Apassword.erase(Apassword.size()-1);
}
else
{
if ( Ainput == ' ' || Ainput == '\\' || Ainput == '|' || Ainput == ',' || Ainput == '<' || Ainput == '.' || Ainput == '>' || Ainput == '/' || Ainput == '?' || Ainput == ';' || Ainput == ':' || Ainput == '\'' || Ainput == '@' || Ainput == '#' || Ainput == '~' || Ainput == ']' || Ainput == '}' || Ainput == '[' || Ainput == '{' || Ainput == '=' || Ainput == '+' || Ainput == '-' || Ainput == '_' || Ainput == ')' || Ainput == '(' || Ainput == '*' || Ainput == '&' || Ainput == '^' || Ainput == '%' || Ainput == '$' || Ainput == '£' || Ainput == '"' || Ainput == '!' )
{
if ( Asize < 50 )
{
cout<<"*";
Apassword += Ainput;
Asize++;
}
}
if ( isalnum(Ainput) && Asize < 50 )
{
cout<<"*";
Apassword2 += Ainput;
Asize++;
}
}
}
Asize = 0;
Ainput = nul;
cout<<"\n\n Confirm Password: ";
while ( Ainput != EOF && Ainput != '\n' && Ainput != '\r' )
{
Ainput = getch();
if ( Ainput == '\b' && Asize > 0 )
{
cout<<"\b \b";
Asize--;
Apassword2.erase(Apassword2.size()-1);
}
else
{
if ( Ainput == ' ' || Ainput == '\\' || Ainput == '|' || Ainput == ',' || Ainput == '<' || Ainput == '.' || Ainput == '>' || Ainput == '/' || Ainput == '?' || Ainput == ';' || Ainput == ':' || Ainput == '\'' || Ainput == '@' || Ainput == '#' || Ainput == '~' || Ainput == ']' || Ainput == '}' || Ainput == '[' || Ainput == '{' || Ainput == '=' || Ainput == '+' || Ainput == '-' || Ainput == '_' || Ainput == ')' || Ainput == '(' || Ainput == '*' || Ainput == '&' || Ainput == '^' || Ainput == '%' || Ainput == '$' || Ainput == '£' || Ainput == '"' || Ainput == '!' )
{
if ( Asize < 50 )
{
cout<<"*";
Apassword2 += Ainput;
Asize++;
}
}
if ( isalnum(Ainput) && Asize < 50 )
{
cout<<"*";
Apassword2 += Ainput;
Asize++;
}
}
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
// End of Setup function.
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Function to read whole file.
////////////////////////////////////////////////////////////////////////////////
bool ReadFile ( string Filename, string &Text )
{
ifstream Read ( Filename.c_str() );
if ( Read )
{
string Temp;
Text.clear();
while ( getline ( Read, Temp ) )
{
Text += Temp;
Text += "\n";
}
Read.close();
}
else
{
Read.close();
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
// End of function.
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// MAIN
////////////////////////////////////////////////////////////////////////////////
int main()
{
ifstream S_Initiation ( "C:/Dev-Cpp/Programs/Random Program Testing/Random/Initiation.txt" );
S_Initiation>> Initiation;
S_Initiation.close();
if ( Initiation != 0 )
{
InitiationFunction();
while ( Apassword != Apassword2 || Apassword == "" || Apassword2 == "" )
{
system("cls");
InitiationFunction();
}
}
cin.get();
}
My problem is that if the user inputs a letter when it first says desired password, and hits backspace, the program outputs some wierd message and then closes so I can't read it. The thing that gets me is that when it says confirm password, it works fine, and as far as I can see, the code is exactly the same except from the variable names.
Also I was doin' some testing on the two password variables, printing them just before the while loop in the main function. The other problem is that I separated them with a new line, but it totally misses out the newline. I also put some text after printing the first variable, but it printed the text first, then a newline, then the variables.
I have got no idea what's going on here. Does this happen to anyone else?
Great thanks to anyone who can help.