password console

hi ive just made my password console application but i cant get it to work can someone help me this is the code




#include <iostream>
#include <string>
using namespace std;

int main()
{

string a;
a= "word" ;// the password
string b;
cout<< "type your password";
cin>> b ;
if (a != b )
{
cout<<"wrong password"<<endl;
cout<<"change your password: yes/no"<<endl;
cin>>l;
if (b="yes")
{
cout<<"type the new password"<<endl;
cin>> a;//the new password
}
else if(b="no" )
goto c;
c:
return 0;
}
else if( a == b)
{
cout<<"welcome";
}
return 0;
}
You can't just equate strings... Use strcmp function defined under string header...
you have no string named l. You use b where you should use l. You use = instead of == inside the if statements. And the goto is completely useless.
thank you about the help
i have some other few questions
what should i do to change the password i mean that after i enter the new password ==> the password should change
Last edited on
You are storing the password in a and you are reading the new password into a so I don't see the problem.
no no ,all i want is that the next time i open the applicatin it has the new password that i typed
In that case you have to store the password somewhere, possibly in a file. You probably want to hash the password so that no one can just open the file and read it.
thats the thing , i dont know how to do that
if you have time can you explain me how to do it?
Last edited on
First you should learn how to read and write from file.

To make something really safe is really hard so if this is just a toy project you might want to use something simple less secure. A good hash function + salt will protect against people stealing your password but if they have your program it wouldn't be hard to hack anyway. I'm not going to explain this in details.
how can i use this function in an application
give me a example
or just give me a link
Last edited on
Use what?

This site has a tutorial about file IO http://www.cplusplus.com/doc/tutorial/files/ (I have no idea if it good or not)
thanks a lot peter87 you are the BEST
Topic archived. No new replies allowed.