DIGIT-ARC read-only archive · snapshot: July 23, 2026

Help Needed In C++ ....... Plz Don't Ignore

15 posts · originally from https://geek.digit.in/community/threads/help-needed-in-c-plz-dont-ignore.47881/

BBThumbHealer
BBThumbHealer Original post #1
Jan 30, 2007 at 12:27 PM
hi frenz......


i m developing a program in turbo C++ v3......now i want the user to enter a password before accessing my program but i don't know how to do this ....


can u ppl help me plz......n temme how to make the code for this purpose !

Thnx....

BlackBerry7100g.
ilugd
ilugd #2
Jan 30, 2007 at 1:16 PM
is that a console program?
If so, then just use something similar to the following
Code:
cout<<"Enter PIN";
cin>>intPin;
if intPin==MACROPIN then 
{
  //call a fn or whatever
}
else
{
cout<<"Access Denied";
return 9;
}
Hope this is what you were looking for.
aditya.shevade
Jan 30, 2007 at 3:30 PM
^^Why return 9?. He can call main again and ask for a password.
anantkhaitan
Feb 1, 2007 at 5:27 PM
frnd u can use this

char a[]="password"; // U Can use ur own
char ch,b[20];
int i=0;
do
{
ch=getch();
b[i++]=ch;
cout<<"*"; // u can use ur own symbol
}while(ch!='\r') // \r has been used for Enter key
b[i-1]='\0';
if(strcmp(a,b)==0)
cout<<"correct"; //here u can use ur program
else
cout<<"access denied";
[/qoute]
ilugd
ilugd #5
Feb 1, 2007 at 7:42 PM
better!!
Garbage
Garbage #6
Feb 2, 2007 at 3:22 PM
^^^^

+1
n2casey
n2casey #7
Feb 2, 2007 at 4:34 PM
Use this code which have some more advantages:

  • Will allow use of Backspace
  • Will not scan Tab key & function keys such as F1, F2, Home, End ... etc.

Code:
#include<string.h>

void main()
{
char c='\0', d='\0', pt[50], ps[]="ur password";
int m=0,n=0;
clrscr();

 while(c!=13)
 {
	c=getch();

	if(c==13)
	{
		for(n; n>=0 ;n--)
		{ pt[m]='\0'; m--; }

		if(strcmp(pt,ps)==0)
		{
		cout<<endl<<"Password accepted."<<endl;
		/*Use ur prog here*/
		}

		else
		cout<<endl<<"Invalid Password!";
	}

	else if(c >31 && c <127)
	{
		for(n; n>0 ;n--)
		{ pt[m]='\0'; m--; }

		pt[m]=c; m++;
	}

	else if(c == 8)
	n++;

	else
	{
	if(c!=9)
	d=getch(); cout<<"\a";
	}
 }
 getch();
}
BBThumbHealer
Feb 2, 2007 at 11:07 PM
hey n2casey....

ur code is workin for which i have repped u too.....

but this is a high level code for me......i m just a beginner to c++ n studying in class XI.....

can u plz make a code which is easily understandable for me....

Thnx...

BlackBerry7100g.
n2casey
n2casey #9
Feb 2, 2007 at 11:30 PM
BlackBerry7100g said:
hey n2casey....

ur code is workin for which i have repped u too.....

but this is a high level code for me......i m just a beginner to c++ n studying in class XI.....

can u plz make a code which is easily understandable for me....

Thnx...

BlackBerry7100g.

Thx for repu.
I will do ur job but don't u think that we can just manipulate this code so that u can understand it.
If u want somewhat different then tell me, what exactly u want.
BBThumbHealer
Feb 3, 2007 at 8:08 PM
hey n2casey......

plz manipulate the code...

Thnx

BlackBerry7100g.
n2casey
n2casey #11
Feb 3, 2007 at 9:52 PM
BlackBerry7100g said:
hey n2casey......

plz manipulate the code...

Thnx

BlackBerry7100g.

OK but which line from this code do u want to understand & which line do u want to manipulate?
ilugd
ilugd #12
Feb 4, 2007 at 2:51 AM
anant's and mine are simple enough aren't they? :-?
BBThumbHealer
Feb 4, 2007 at 11:51 AM
hey ilugd and anant.....

ur codes were gr8 too for which i have repped u both.....


and,aditya.shevade.........ur avatar is too cool man...

Thnx....

BlackBerry7100g.
n2casey
n2casey #14
Feb 4, 2007 at 1:24 PM
^^
So ur prob solved. Nice to know that.
aditya.shevade
Feb 4, 2007 at 10:15 PM
BlackBerry7100g said:
aditya.shevade.........ur avatar is too cool man...

Thnx....

BlackBerry7100g.

Thanks man. You have no idea what I and Vimal had been going through regarding my avatar.

Aditya