password code

justice igwe -3 Tallied Votes 394 Views Share

well am using the turbo c++ compiler , so you must convert it to cpp ( c++)
before u can use it ok. here we go.
steps:
(1)press the windows shortcut key and hold R or go click on RUN
(2) type in the following( C:/TC/BIN/TC.EXE) hit ENTER, wait for 5 seconds and then press f3 on the keboard.
(2) rename it to ur choice, but the extension should be in cpp eg..
(3) test.cpp or code.cpp. it should not be in tect.c or code.c
(4) there should be a #include<conio.h> header after #include<iostream.h>
WHAT THE CODE DOES:
this code will prompt for a password, but the character inputed will not be displayed,rather it replaces it with an asteriks so that the password becomes invisible to any user except YOU..
Headers like IOMANIP.H was included to manipulate the output .. i think with this code you can help yourselves out and write a protective program that cannot be accessed easily..
make sure u have a TURBO C++ compiler thanks enjoy it anything else just let me know......

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
main()
{
char choice;
char n,i;
int y,z,sum;
char x;
clrscr();
loop:clrscr();
cout<<endl<<" Enter Your Password..... <  >   ";
gotoxy(21,2);
n=getch();
cout<<"*";
if(n!='y')
{
cout<<"\n Wrong Access Code \n\n Hit The ENTER key To continue ";
getch();
goto page:
}
else
{
cout<<"\n Access Granted.....\n\n Hit The ENTER key To Continue    ";
getch();
clrscr();
cout<<"\n  C++ calculator Programmed By Igwe Justice Chikaodi ";
cout<<"\n Main Menu  ";
gotoxy(20,4);cout<<"\n Press (a) for Addition \n Press (b) for Multiplication \n  Enter Choice  < >  ";
gotoxy(17,7);
cin>>x;
switch(x)
{
case 'a':clrscr();
cout<<"\n Addition Department :  :  ";
cout<<"\n Enter Two Numbers     ";
cin>>y>>z;
sum=( y+z);
cout<<"\n The Sum of "<<y<<" and "<<z<<" is "<<setw(6)<<sum<<endl;
cout<<"\n Thank You ";
getch();
break;
case 'm':clrscr();
cout<<"\n Multiplication Department :  :  ";
cout<<"\n Enter Two Numbers     ";
cin>>y>>z;
sum=( y*z);
cout<<"\n The Procuct of "<<y<<" and "<<z<<" is "<<setw(6)<<sum<<endl;
cout<<"\n Thank You ";
getch();
break;
default:
cout<<"\n Hope U enjoyed The Calculator    ";
}
page:clrscr();
cout<<"\n Do You want To Continue again (y/n) :  ";
cin>>choice;
if((choice=='y')||(choice=='Y'))
{
goto loop;
}
else if((choice=='n')||(choice=='N'))
{
cout<<"\n ThanK You For Using Igwe's Program ";
}
}
getch();
}

Dani AI

Generated

’s sample is a useful learning exercise, but it needs a few practical fixes before it’s used or reused. correctly flagged the single-character password and the poor use of goto. fixed a typo, but the program still mixes Turbo‑C console tricks (conio.h, clrscr, gotoxy, getch) with obsolete headers like iostream.h, which makes the code non‑portable and fragile.

Key problems to address:

  • The “password” is one char and is hardcoded (comparison to 'y'). That’s not real authentication.
  • Prompt text and switch cases don’t match (prompt shows b but code checks m).
  • Non‑standard APIs (conio) and old headers are compiler‑specific; modern code should use standard headers.
  • goto makes flow hard to follow — use loops/functions instead.
  • main lacks a proper return type and there’s no input validation or error handling.

A practical modernization path:

  • Replace old headers with standard ones (<iostream>, <string>, <iomanip>), use int main(), and avoid goto.
  • Accept multi‑character passwords via std::string and validate them. For masking on POSIX terminals, disable echo with termios; on Windows use _getch() or console APIs.
  • Never hard‑code credentials; store hashes or use configuration.
  • Validate numeric input for the calculator (check stream state or parse with std::stoi).

Example (POSIX password input, original to this thread):

#include <iostream>
#include <string>
#include <termios.h>
#include <unistd.h>

std::string getPassword() {
    termios oldt{};
    tcgetattr(STDIN_FILENO, &oldt);
    termios noecho = oldt;
    noecho.c_lflag &= ~ECHO;
    tcsetattr(STDIN_FILENO, TCSANOW, &noecho);
    std::string pw;
    std::getline(std::cin, pw);
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
    return pw;
}

Additional tips: compile with a modern compiler (g++, clang or MSVC) and -std=c++17 -Wall -Wextra; replace goto with well‑scoped loops or functions; and, if security matters, avoid keeping passwords in plain memory (overwrite buffers after use, and store hashes rather than raw strings). This keeps the learning value of the original demo while making the code maintainable and portable.

rahul8590 71 Posting Whiz

1. People need not to have a single character as a password , ur code works only for a single character.

2. Goto is a very very bad & unstructured style of programming , double whammies like that are rare.

3.For , god sake stop using the old freaking turbo C++ compiler , there are much better compilers like gcc, boroland etc.

commented: 3 EXCELLENT points! +18
commented: Yes-Please recycle anything else except for Borland code +1
CppBuilder2006 -5 Junior Poster

Even the latest version of Borland C++ supports an old code written for turbo C 1992!

the code had a simple misprint, I corrected:

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
main()
{
	char choice;
	char n, i;
	int y, z, sum;
	char x;
	clrscr();
loop:
	clrscr();
	cout << endl << " Enter Your Password..... <  >   ";
	gotoxy(21, 2);
	n = getch();
	cout << "*";
	if (n != 'y')
	{
		cout << "\n Wrong Access Code \n\n Hit The ENTER key To continue ";
		getch();
		goto page;
	}
	else
	{
		cout << "\n Access Granted.....\n\n Hit The ENTER key To Continue    ";
		getch();
		clrscr();
		cout << "\n  C++ calculator Programmed By Igwe Justice Chikaodi ";
		cout << "\n Main Menu  ";
		gotoxy(20, 4);
		cout << "\n Press (a) for Addition \n Press (b) for Multiplication \n  Enter Choice  < >  ";
		gotoxy(17, 7);
		cin >> x;
		switch (x)
		{
			case 'a':
				clrscr();
				cout << "\n Addition Department :  :  ";
				cout << "\n Enter Two Numbers     ";
				cin >> y >> z;
				sum = ( y + z);
				cout << "\n The Sum of " << y << " and " << z << " is " << setw(6) << sum << endl;
				cout << "\n Thank You ";
				getch();
				break;
			case 'm':
				clrscr();
				cout << "\n Multiplication Department :  :  ";
				cout << "\n Enter Two Numbers     ";
				cin >> y >> z;
				sum = ( y * z);
				cout << "\n The Procuct of " << y << " and " << z << " is " << setw(6) << sum << endl;
				cout << "\n Thank You ";
				getch();
				break;
			default:
				cout << "\n Hope U enjoyed The Calculator    ";
		}
page:
		clrscr();
		cout << "\n Do You want To Continue again (y/n) :  ";
		cin >> choice;
		if ((choice == 'y') || (choice == 'Y'))
		{
			goto loop;
		}
		else
			if ((choice == 'n') || (choice == 'N'))
			{
				cout << "\n ThanK You For Using Igwe's Program ";
			}
	}
	getch();
}

for a longer password you should add a loop.

Member #46692 commented: nope -2
justiceigwe 0 Newbie Poster

thanks alot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.