Thread: Issue while trying to encrypt login system

  1. #1
    Registered User
    Join Date
    May 2019
    Posts
    47

    Exclamation Issue while trying to encrypt login system

    hello freinds,
    I am new to c++ and was fololwing a login system tutorial

    everything worked fine till i tried to add encryption

    before encryption
    this actually works and reading data perfectly from users.dat and passwords.dat
    Code:
    #include<iostream>#include<fstream>
    
    
    using namespace std;
    
    
    class loginManager{
      public:
        loginManager(){
            accessGranted =0;
        }
      void login()
      {
          cout<<"Hey you need to enter your username and password here\n Username:";
          cin>>userNameAttempt;
    
    
          userName = getFile("users.dat");
    
    
          if(userNameAttempt==userName)
            {
                cout<<"Password: ";
                cin>>passwordAttempt;
                password = getFile("passwords.dat");
    
    
                if(passwordAttempt==password)
                {
                    cout<<"you are logged in"<<endl;
                    cin.get();
                }
                else
                {
                   cout<<"wrong password"<<endl;
                   login();
                }
            }
            else
            {
                cout<<"wrong username"<<endl;
                login();
            }
      }
      string getFile(const char* p_fileName)
      {
          string line;
          fstream file;
          file.open(p_fileName, ios::in);
          if(file.is_open())
            {
              getline(file,line);
            }
          file.close();
          return line;
      }
    
    
      private:
        string password;
        string userName;
        string userNameAttempt;
        string passwordAttempt;
        bool accessGranted;
    };
    int main(){
    
    
     loginManager loginManagerObj;
     loginManagerObj.login();
     cin.get();
    return 0;
    }

    after encryption

    Code:
    #include<iostream>#include<fstream>
    
    
    using namespace std;
    
    
    class loginManager{
      public:
        loginManager(){
            accessGranted =0;
        }
      void login()
      {
          cout<<"Hey you need to enter your username and password here\n Username:";
          cin>>userNameAttempt;
    
    
          userName = getFile("users.dat");
    
    
          if(userNameAttempt==userName)
            {
                cout<<"Password: ";
                cin>>passwordAttempt;
                password = getFile("passwords.dat");
    
    
                if(passwordAttempt==password)
                {
                    cout<<"you are logged in"<<endl;
                    cin.get();
                }
                else
                {
                   cout<<"wrong password"<<endl;
                   login();
                }
            }
            else
            {
                cout<<"wrong username"<<endl;
                login();
            }
      }
      string getFile(const char* p_fileName)
      {
          string line;
          fstream file;
          file.open(p_fileName, ios::in);
          if(file.is_open())
            {
              getline(file,line);
            }
          file.close();
          return line;
      }
      void saveFile(string p_line,const *p_fileName)
      {
          fstream file;
          file.open(p_fileName,ios::out);
          for(int i=0;i<p_line.length();i++)
          {
               file<<encrypt(p_line[i]);
               file<<"\n";
          }
          file<<"0";
          file.close();
    
    
      }
      int encrypt(int p_letter)
      {
          return p_letter + 3;
      }
      int decrypt(int p_letter)
      {
          return p_letter - 3;
      }
    
    
      private:
        string password;
        string userName;
        string userNameAttempt;
        string passwordAttempt;
        bool accessGranted;
    };
    int main(){
    
    
     loginManager loginManagerObj;
     loginManagerObj.saveFile("grapejuice","passwords.dat");
     cin.get();
    return 0;
    }
    i just ran this code to check if the encryption works or not but
    it gives error on this line
    Code:
     file.open(p_fileName,ios::out);
    saying no matching function for call

    what am i missing here?
    Last edited by sash_007; 12-02-2019 at 09:06 PM.

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,628
    When you look at the errors that the compiler spits out, always scroll back to the very first one and deal with that one first. The first error your compiler should mention is that in the function saveFile, p_filename has no type! It's just const *p_filename but should be const char *p_filename.
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple login and registration system
    By daviddiniss in forum C Programming
    Replies: 1
    Last Post: 12-21-2018, 07:12 AM
  2. Replies: 8
    Last Post: 12-08-2009, 12:55 PM
  3. Strange issue utilizing encrypt() in libcrypt
    By TheComedian in forum C Programming
    Replies: 8
    Last Post: 01-18-2009, 07:14 AM
  4. Login System
    By legit in forum C++ Programming
    Replies: 6
    Last Post: 11-22-2008, 09:38 AM
  5. creating a user login system for web pages
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-04-2002, 11:02 PM

Tags for this Thread