1 Replies - 317 Views - Last Post: 07 October 2012 - 02:29 AM Rate Topic: -----

#1 ijazahmad  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 06-October 12

want to login with the old username i saved in the file doesnt work

Posted 06 October 2012 - 11:56 PM

#include<iostream>
#include<fstream>
#include<conio.h>
#include<string>
using namespace std;
class user
{
public:
	int pswrd,age;
	
string inuser;
string inpass;
string userr;
string pass;
	string username,name,fname,adress;
	void password()						//this function will save userpassowords
										//registering the user
	{
		ofstream pass("pasword.txt",ios::binary|ios::out|ios::app);
		pass<<"\n"<<pswrd;
		pass.close();
		
	}
	void user_name()
	{
		ofstream user("usernamee.txt",ios::binary|ios::out|ios::app);
		user<<username<<endl;
		user.close();
	}
	void profile()
	{
		ofstream prof("userprofile.txt",ios::binary|ios::out|ios::app);
		prof<<name<<"\t"<<fname<<"\t"<<age<<"\t"<<adress<<"\n\n";
		prof.close();
	}
	
	void login()
	{
	 ifstream Passfile("password.txt", ios::in);
     Passfile>>inpass;
     ifstream Userfile("username.txt", ios::in);
     Userfile>>inuser;
     
     cout<<"USERNAME: ";
     cin>>userr;
     cout<<"PASSWORD: ";
     cin>>pass;
     Userfile.close();
     Passfile.close();
     if(userr==inuser&&pass==inpass) 
     cout<<"\naccess granted";
	 else
		 cout<<"wrong password";
	 getch();

	 

	}


};


void main()
{
	user user1;
	char ch;
	cout<<"(1)login\n\n(2)register\n";
	cin>>ch;
			
	switch(ch)
	{
	case '2':

	cout<<"enter your username:";
	cin>>user1.username;
	user1.user_name();

	cout<<"\nenter your password:";
	cin>>user1.pswrd;
	user1.password();
	
	cout<<"\nenter your name:";
	cin>>user1.name;
	cout<<"\nenter your father name:";
	cin>>user1.fname;
	cout<<"\ncout enter your age :";
	cin>>user1.age;
	cout<<"\nenter your adress:";
	cin>>user1.adress;
	user1.profile();
	cout<<"\n\n registration was successfull ";
	break;
	case '1':
		user1.login();
		break;
	getch();
	}

}


please help any body

This post has been edited by Salem_c: 07 October 2012 - 12:26 AM
Reason for edit:: added [code][/code] tags - learn to use them yourself


Is This A Good Question/Topic? 0
  • +

Replies To: want to login with the old username i saved in the file doesnt work

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: want to login with the old username i saved in the file doesnt work

Posted 07 October 2012 - 02:29 AM

Check your spelling of filenames. Are you sure you want to save text as binary?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1