How to set a password?

Pages: 12
ziodice wrote:
Is there a way to make multiple passwords, so that different users could get in to the program and resume their last session?

You will have to store each user's session information in a file (you could use one for all users or one file for each user). You will need to make the info easily parsable for your program. You may want to use XML and use an XML parser library.

e.g. (UserData.txt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
UserName: ziodice
Password: *******
SessionInfo:
var1 = var1Value
var2 = var2Value
//more session info
End ziodice

UserName: TheMassiveChipmunk
Password: WEEZER
SessionInfo:
var1 = var1Value
var2 = var2Value
//more session info
End TheMassiveChipmunk


ziodice wrote:
Wait...is it possible to have a program MAKE a text file, then let you set the password, then let you enter the program?

Yes. If you use std::ofstream, and the file can't be found, it makes the file for you. Make sure the directory structure you're using in the path is valid though.
Last edited on
Maybe if I make text files, when it starts, it looks in the text files, looks at each of the passwords, then, depending on the password you enter , it looks in the specific text file, looks at a number, depending on the number, it skips to a certain part of the program? And then it says "Hello, <username>, welcome back to <program name>"? And whats parsing/parser/parsable?
And whats parsing

Essentially, "making sense of something". A file parser would open a file and take in input from it. When structuring a text file for input, you should be sure that the program can find what it wants easily (i.e. that it is easily parsed).

it looks in the text files, looks at each of the passwords, then, depending on the password you enter , it looks in the specific text file

Or, you can give them a user name (or user ID) and use that to determine which file/where in the file to look for the info.

depending on the number, it skips to a certain part of the program?

For that to work, you should be sure that it can start running from that part of the program cleanly. For instance, you might not be able to just jump there without initializing some variables that are expected to be in a certain state at that point. For console programs, this may be a bit of an issue. For GUI programs though, it would just be a matter of saving the states of all the (relevant) controls when saving, and just loading them back on re-entrance.
Last edited on
I only know console. What exactly IS GUI? and how would I go about learning that?
If you want to create a file and then add passwords to it later maybe you can look at the append mode in ofstream (ios::app)
1
2
3
4
5
6
7
8
9
10
11
#include <fstream>
using namespace std;

int main ()
{
	ofstream File;
	File.open ("NothingHere.NothingHereFolks" , ios::app);
	File << "Secret Information." << endl;
	File.close ();
	return 0;
}

GUI means "Graphical User Interface". You interact with one whenever you use your computer (I assume you're not using a text-only OS).

http://en.wikipedia.org/wiki/Graphical_user_interface

GUI programming is quite the step from console programming (in C++), so be sure you have a solid grasp of the language before proceeding. A good, cross-platform GUI library that's often-recommended is Qt.

http://qt.nokia.com/products/

On Windows, you could also use the WinAPI (warning: it's cumbersome).

http://en.wikipedia.org/wiki/Windows_API
http://msdn.microsoft.com/en-us/library/ms633559(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/ms632680(v=VS.85).aspx
Last edited on
You can try WinAPI and after you become comfortable with it you can use MFC which is a lot easier.
To learn WinAPI I recommend http://www.winprog.org/tutorial/
@shacktar I never knew about Qt. Is it easy?
Last edited on
I haven't used it myself but it looks easy.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <QApplication>
#include <QPushButton>

int main(int argc, char *argv[])
{
     QApplication app(argc, argv);

     QPushButton hello("Hello world!");
     hello.resize(100, 30);

     hello.show();
     return app.exec();
}


http://doc.qt.nokia.com/4.3/tutorial-t1.html
Wow I am going to check out thanks for showing to me.
Edit I am not sure if they changed their name but there are a lot of banners that say TrollTech lol
Last edited on
So.....I should wait until I've almost mastered console first? Which I know I am a LONG way from.
And you mean, like, windows? Like my internet browser window would be a gui thingy?
In my first programming class (Pascal) we started GUI programming after around two thirds of the year was done. We were doing procedural programming (no objects) and we really just had just covered the basics (data types, variables, console I/O, procedures/functions, if/else, loops) before moving onto GUI. The GUI library we used was very simple though and we didn't need to know anything but the basics to use it.

For C++ GUI programming, you will need to know more than just the basics to proceed comfortably. It would be in your best interest to at least learn the basics + classes, inheritance, and dynamic memory before moving onto GUI.

ziodice wrote:
I should wait until I've almost mastered console first?

Not mastered, but at least very comfortable with it. Mastery is asking too much.

ziodice wrote:
Like my internet browser window would be a gui thingy?

Yes. If you open the command prompt (or shell on *nix) then you're interacting with a console. If you do practically anything else, then you're interacting with a GUI. A GUI version of your program would have a window with two textboxes (one for the user name and one for the password) at the start of the program, for example.

TheMassiveChipmunk wrote:
I am not sure if they changed their name but there are a lot of banners that say TrollTech

That's their name, apparently.

http://doc.qt.nokia.com/4.3/trolltech.html
Last edited on
Trolltech. Thats really funny. Now I have to figure out something cool for my program to DO.....like, whats the point in making a program that makes you enter a password if it just prints something? Gah. Any ideas, peoples?
OOOH. it could be, like, a diary almost. You write it into the program, saves it in a text file, and to get INTO the diary, you have to put in the password
Last edited on
closed account (zb0S216C)
ziodice wrote:
Any ideas, peoples? (sic)

How about a word recognition program? Simply determine whether the word is a swear word, a made-up word, etc.

Wazzak
Hey, that QT trolltech stuff is pretty easy!
Topic archived. No new replies allowed.
Pages: 12