Hi, I want to write a program that can be used to read a password, then save it in the memory, and if the password is correct, later, then allowing access to the user, and otherwise denying access. But the problem is that I don't know what functions, or header files I have to use for this. I mean, string.h is required, but anything else? Please help... Thanks
No, you don't need string.h. You probably meant string.
Read a password from where? How do you determine whether the password is correct? When is later? Allowing or denying access to what?
What do you mean by "save in the memory"? Since every variable is saved to memory, you can simply assign the password to a variable.
But if you want to save the password after user closes the program, then the easiest way that I can think of is to cypher the password and data and save it to a file.
Hey thanks fresh grass, but I haven't learned the <fstream> header file. What does it do? What are its functions? And I am using a turbo C++ ide, so I can't type #include<fstream>. I got to write, #include<fstream.h>.
anyway, look at this, this is what i have done. And what I meant wen i said "saving" was... uu know... you have to input a password to your mail id and all, u know... I can't explain well, but hope you got the idea. Anyway, take a look at my program:
#include<iostream.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
char a[30],b[30],c[30];
int pass;
clrscr();
cout<<"Enter your password\n";
cin.getline(a,30);
clrscr();
cout<<"Enter the password\n";
cin.getline(b,30);
if(strcmp(a,b))
{
cout<<"Wrong password.\n1.try again\t2.quit\n";
cin>>pass;
switch(pass)
{
case 1:
clrscr();
cout<<"Enter the password\n";
cin.getline(c,30);
if(strcmp(a,c))
{
cout<<"Wrong password. Program quitting";
exit(0);
}
else
{
int d,g,w;
cout<<"Enter two numbers\n";
cin>>d>>g;
if(g>d)
{
(w==0)?cout<<"the greatest number is "<<g<<" and it is even" : cout<<"The greatest number is "<<g<<" and it is odd";
}
else
{
w=d%2;
(w==0)?cout<<"The greatest number is "<<d<<" and it is even" : cout<<"The greatest number is "<<d<<"and it is odd";
}
break;
case 2:
clrscr();
cout<<"Program quitting";
exit(0);
break;
default:
cout<<"Please choose from the above two options";
goto s;
}
}
}
else
{
int p,o,k;
cout<<"Enter two numbers\n";
cin>>p>>o;
if(p>o)
{
k=p%2;
(k==0)?cout<<"The greatest number is "<<p<<" and it is even":cout<<"The greatest number is "<<p<<" and it is odd";
}
else
{k=o%2;
(k==0)?cout<<"The greatest number is "<<o<<" and it is even":cout<<"The greatest number is "<<o<<" and it is odd";
}
}
s:
{cout<<"sorry. Try again later";
}
getch();
return 0;
}
You know, the last part is only for letting me know that the program has run well. Just look at the last part. But I do get a runtime error. It runs alright til it reaches the switch statement. Then ot runs only if the password is right. Can you tell me the problem? And the correction? Anything I tried won't give me the results I wanted. And I know only the header files <iostream>, <conio>, <math>, <string>, and <ctype>, and I used the <stdlib> for fun( you won't believe it), but when I took it away, it showed an error that exit(0) needed a prototype. Haha.
Anyway, please help, and thanks. Kay.
Can you please explain your program to me too? I didnt really get it, but i'll try to understand as much as i can, all the same. Bye. Thanks...
And Athar, I came here in the first place to get advice on how to know if the password is wrong. And for the rest of your questions, I am sure you could use a bit of commonsense. Later means, at any point in future, as long as the program exists in the computer memory. Read a password from where? We input it, of course, how else. Please read the program I have written and you'll get a pretty good idea of what i meant. And please help me with the correction of the program. As i said, there is a runtime error that occurs while I run it. Anyway, I have only a turbo C++ 3.0 ide, so I cant go typing <string>. Please hepl...
Hey, Athar, you're an idiot for misunderstanding obvious stuff... Please take a look at the very obvious, simple, code I have (which you should have kythed from me to begin with) and help me fix it. Plzzzzz.
You are kidding, right? Where do you losers keep coming from? Do you really think that it is wise to bite the hands helping you?
Athar asked all very good, relevant information. He obviously understands a great deal more about password handling and secure systems than you do. Given his apparent good nature, he did something common among professionals and asked for more information about your (very vaguely worded) problem, so that he could better help you.
Perhaps you might consider, for future use, that the people who respond to your plea for help might actually know more about the subject than you do, and have no ulterior motive than to best help you.