(The code isn't complex as it's for my school project.)
It is a function that is used for entering the password to login. If the password has been created, the user enters it, else they are prompted to create a password.
1 2 3 4
while(!ReadFile)
{
cnt++;
}
It's used to find the length of the file "Pass". If it contains any characters, the cnt gets updated.
1 2 3 4 5 6 7 8 9 10 11 12
if(cnt==-1){//Create A Password, if it doesn't exist yet.
ofstream WriteToFile("pass",ios::out);
cout<<"You haven't set the password yet. Please set it now.";
cout<<"Enter a New Password (Maximum of 20 characters)";
gets(newpass);
for(int i=0;i!='\0';i++)
{
WriteToFile<<newpass[i];
}
WriteToFile.close();
return 1;
}//PASSWORD CREATED!
If cnt wasn't updated, User is prompted to create the password. The function then returns 1.
If the cnt was updated (means that password has been created before), the user is prompted to enter it. If it matches with the password saved in the file, the function returns 1, else 0.