9 Replies - 3489 Views - Last Post: 09 September 2010 - 01:33 PM Rate Topic: -----

#1 Doomsater  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-September 10

C++ Win32 application - Password protection

Posted 09 September 2010 - 11:39 AM

Hi, basically the problem is that i am making a rather large program and one of the features is that the user must enter their username and password to be able to access the other parts of the program. I have worked out how to do this code (see below) but the problem is that i would like to give the user the option to change the password to whatever they would like. Any ideas? Please note that this is a C++ win32 application NOT a console program. The compiler I use is Borland C Builder 4.

if(Edit1->text = "password");
        MainForm->ShowModal;
      else (gives an error message)


Is This A Good Question/Topic? 0
  • +

Replies To: C++ Win32 application - Password protection

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: C++ Win32 application - Password protection

Posted 09 September 2010 - 11:46 AM

What exactly are you struggling with, then?
Was This Post Helpful? 0
  • +
  • -

#3 Doomsater  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-September 10

Re: C++ Win32 application - Password protection

Posted 09 September 2010 - 11:55 AM

Well, how would i do the coding which allows the user to change the password to whatever they want, and ensure that that change is permanent (unless changed again).
Was This Post Helpful? 0
  • +
  • -

#4 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: C++ Win32 application - Password protection

Posted 09 September 2010 - 12:02 PM

Clearly, you can't hardcode a password, as it's not fixed. Instead, you should be storing the password somewhere on disk permanently, as that's how it will persist, right? If you store the password somewhere, you can, when your program starts up, read the password from disk.
Was This Post Helpful? 0
  • +
  • -

#5 Doomsater  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-September 10

Re: C++ Win32 application - Password protection

Posted 09 September 2010 - 12:09 PM

Exactly so, but how would i do this in code? I have seen different ways to do it if it were a console program but i cannot think of how to do it in win32...
Was This Post Helpful? 0
  • +
  • -

#6 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: C++ Win32 application - Password protection

Posted 09 September 2010 - 12:12 PM

Aside from program initialization (e.g. you don't get an allocated console), a console vs. a non-console app aren't different. You can't read or write to console, but everything else is the same.

I'm not sure what the problem is. In fact, why don't you tell us what you would do if this were a console application?
Was This Post Helpful? 0
  • +
  • -

#7 Doomsater  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-September 10

Re: C++ Win32 application - Password protection

Posted 09 September 2010 - 12:24 PM

Well i did find this which needs you to create two text files where the username and password are stored. It checks that the input is correct and also has a utility to change them as well.

#include<iostream>
#include<fstream>
#include<conio.h>

using namespace std;

void Auth();
void Members();
void Userchange();
void Passchange();

string inuser;
string inpass;
string user;
string pass;
int num = 0;
string com;

main()
{
      system("cls");
      cout<<"Welcome\n---------------------------\n\n";
      while(num==0)
      {
      system("cls");
      cout<<"Command: ";
      cin>>com;
      if(com=="login")
      {
      Auth();
      }
      else if(com=="change-pass")
      {
           Passchange();
           }
      else if(com=="change-user")
      {
           Userchange();
           }
      else if(com=="credits")
      {
           cout<<"written by ..."; 
           }
      else if(com=="exit")
      {
           cout<<"goodbye";
           getch();
           break;
           }
      else if(com==com)
      {
           cout<<"Unknown command\n";
           }
      }
}
void Auth()
{
     ifstream Passfile("password.txt", ios::in);
     Passfile>>inpass;
     ifstream Userfile("username.txt", ios::in);
     Userfile>>inuser;
     system("cls");
     cout<<"USERNAME: ";
     cin>>user;
     cout<<"PASSWORD: ";
     cin>>pass;
     Userfile.close();
     Passfile.close();
     if(user==inuser&&pass==inpass)
     {
     cout<<"\nHit enter to continue to members area";
     getch();
     Members();
     }
     else
     {
         cout<<"nope";
         getch();
         main();
         }
}
void Userchange()
{
     string tempass;
     system("cls");
     cout<<"enter current password: ";
     cin>>tempass;
     if(tempass==inpass)
     {
     cout<<"utility to change username stored in file\n";
     cout<<"CHANGE USER TO: ";
     cin>>user;
     ofstream Userfile("username.txt", ios::out);
     Userfile<<user;
     Userfile.close();
     cout<<"Username successfully changed";
     getch();
     main();
}
else
{
    cout<<"Invalid Password";
    getch();
    main();
}
}
void Passchange()
{
     string tempass;
     system("cls");
     cout<<"enter current password: ";
     cin>>tempass;
     if(tempass==inpass)
     {
     cout<<"utility to change password stored in file\n";
     cout<<"CHANGE PASS TO: ";
     cin>>user;
     ofstream Passfile("password.txt", ios::out);
     Passfile<<user;
     Passfile.close();
     cout<<"password successfully changed";
     getch();
     main();
}
else
{
    cout<<"Invalid Password: ";
    getch();
    main();
}
}
void Members()
{
     cout<<"nothing";// put members code here
     // like a while(){} loop or somethin like that
     // comment please
}

Was This Post Helpful? 0
  • +
  • -

#8 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: C++ Win32 application - Password protection

Posted 09 September 2010 - 12:36 PM

All you did was copy paste a DIC snippet. And your description of what this code does is basically a rephrase of the DIC webpage description.

This is a horrible snippet of code, by the way. Whoever posted it intended for it to be a tutorial, but it's a prime example of why enthusiastic beginners should focus on learning, not teaching. Don't emulate it.

To be honest, it largely seems like you don't know how to program. In fact, what you seem to want is copy pastable code, which I won't give out.

I wanted you to describe the steps you would take in a console program, but you aren't able to do that. Until you can clearly do so, in plain English, there isn't much to say, other than that you should revisit programming basics.
Was This Post Helpful? 1
  • +
  • -

#9 Doomsater  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-September 10

Re: C++ Win32 application - Password protection

Posted 09 September 2010 - 01:08 PM

Yes i did cap that code but i thought it might give you an idea of what im struggling with. Im sorry but i am relatively new to programming and my knowlege is rather limited compared to other people such as yourself. I do not expect you to give me the coding for it as i do wish to work things out for myself, just a hint in the right direction might trigger it to come to me.

I have just thought of this:

String S = "password";

if(Edit1->text = S);
 MainForm->ShowModal;

else (give error message)


and then when the user wants to change the password:

S = Edit2->text;


i feel that if this did work, it would not be a permanent change
Was This Post Helpful? 0
  • +
  • -

#10 Alex6788  Icon User is offline

  • kitties == adorable


Reputation: 144
  • View blog
  • Posts: 1,667
  • Joined: 15-July 10

Re: C++ Win32 application - Password protection

Posted 09 September 2010 - 01:33 PM

Quote

Yes i did cap that code but i thought it might give you an idea of what im struggling with. Im sorry but i am relatively new to programming and my knowlege is rather limited compared to other people such as yourself. I do not expect you to give me the coding for it as i do wish to work things out for myself, just a hint in the right direction might trigger it to come to me.


You should stick with console apps then before jumping right into GUI programming. There's a lot of fun and cool things you can do with console apps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1