PDA

View Full Version : Saving a password in a file



srohit24
24th June 2009, 13:09
Hi

I am writing a application, that takes the username and password from the user.

I want to add a feature that helps in remembering the username and password.

What i have thought was, storing the username and password in encrypted form in a file on the disk.

how will Qt support creating the file and storing it?

Where can I store the file? near the app or in My Documents/All User/ ... folder?

one more thing, How can i invoke a pop-up box to accept some text?

thanks

spirit
24th June 2009, 13:32
take a look at QCA (http://delta.affinix.com/qca/). then you should provide a master key for encryption users passwords, after that when you encrypt an users password you should to convert encrypted password in base64 (this opperation will help to avoid dencrypt an user password in future, i.e. converting to base64 allows to convert special symbols). then you can store password to a file.

srohit24
24th June 2009, 13:50
thanks for replying so soon :)

What i need mainly is how to create a file and how to extract the data from it.

spirit
24th June 2009, 13:53
there is an example in Qt Assistant, take a look at QFile/QTextStream or QSettings.

srohit24
24th June 2009, 14:12
Thanks for this.

Isnt there a simple command for it?

Like

File.create(test.txt, $location); to create a file
File.open(file, mode);
File.read(file,start add, no of chars);
File.write(file,mode,string,no of chars);

thanks for ur help :)

wysota
24th June 2009, 15:14
What i have thought was, storing the username and password in encrypted form in a file on the disk.
That's generally a bad idea because you have to store the key somewhere...


Where can I store the file? near the app or in My Documents/All User/ ... folder?
Store it wherever you want :) QDesktopServices::storageLocation() might be a handy method here.


one more thing, How can i invoke a pop-up box to accept some text?
QInputDialog::getText()



Isnt there a simple command for it?

Like

File.create(test.txt, $location); to create a file
File.open(file, mode);
File.read(file,start add, no of chars);
File.write(file,mode,string,no of chars);


Sure there is, use QFile as suggested, although it would probably be better if you used QSettings (as suggested as well).

srohit24
24th June 2009, 16:05
thanks for helping mate. :)

the getText() thing worked fine.

Both of you have been telling me to use QFile with QSettings, can you just give me a simple example as to how i can accomplish it?

All i need is a simple file that holds 3 lines of text. I need to access all 3 lines, modify it or delete it.

I went through the documentation, there are very few examples and those haven t helped me understand much.

thanks :D

spirit
24th June 2009, 16:11
storing to QSettings


QSetting settings("settings.ini", QSettings::IniFormat);
settings.setValue("UserOption/login", "login");
settings.setValue("UserOption/password", "passw");

reading to QSettings


QSetting settings("settings.ini", QSettings::IniFormat);
qDebug() << settings.value("UserOption/login");
qDebug() << settings.value("UserOption/password");

srohit24
24th June 2009, 17:45
thanks mate. the above code worked according to my needs.

I am trying to get a signal when the checkbox in my app is clicked.

I am using the following code.

connect(ui->checkbox, SIGNAL(stateChanged()),SLOT(checkboxclicked()));

but the function is never called even if i check or uncheck the box

any solutions??

Lykurg
24th June 2009, 18:00
any solutions??
Yepp, read the docs, validate your code... and use the CODE tags of this board!

To your question: You missed this

connect(ui->checkbox, SIGNAL(stateChanged()), this, SLOT(checkboxclicked()));

and is checkboxclicked declared as a slot?

EDIT: and mybe you also want:
connect(ui->checkbox, SIGNAL(stateChanged(int)), this, SLOT(checkboxclicked(int)));

srohit24
24th June 2009, 18:13
thanks for ur reply :)

wysota
24th June 2009, 20:47
I'd use toggled() instead of stateChanged().

faldzip
25th June 2009, 08:50
To your question: You missed this
this is not necessary. There is such connect() that takes 3 args: pointer, signal, slot. And that slot should be defined in object ponited by this.

And to srohit24:
please, use CODE tags, and use the Qt Assistant sometimes, did you use it already?