Results 1 to 13 of 13

Thread: Saving a password in a file

  1. #1
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Saving a password in a file

    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

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Saving a password in a file

    take a look at 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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Saving a password in a file

    thanks for replying so soon

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

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Saving a password in a file

    there is an example in Qt Assistant, take a look at QFile/QTextStream or QSettings.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Saving a password in a file

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Saving a password in a file

    Quote Originally Posted by srohit24 View Post
    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()

    Quote Originally Posted by srohit24 View Post
    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    srohit24 (24th June 2009)

  8. #7
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Saving a password in a file

    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
    Last edited by srohit24; 24th June 2009 at 15:10.

  9. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Saving a password in a file

    storing to QSettings
    Qt Code:
    1. QSetting settings("settings.ini", QSettings::IniFormat);
    2. settings.setValue("UserOption/login", "login");
    3. settings.setValue("UserOption/password", "passw");
    To copy to clipboard, switch view to plain text mode 
    reading to QSettings
    Qt Code:
    1. QSetting settings("settings.ini", QSettings::IniFormat);
    2. qDebug() << settings.value("UserOption/login");
    3. qDebug() << settings.value("UserOption/password");
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  10. The following user says thank you to spirit for this useful post:

    srohit24 (24th June 2009)

  11. #9
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Saving a password in a file

    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??

  12. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Saving a password in a file

    Quote Originally Posted by srohit24 View Post
    any solutions??
    Yepp, read the docs, validate your code... and use the CODE tags of this board!

    To your question: You missed this
    Qt Code:
    1. connect(ui->checkbox, SIGNAL(stateChanged()), this, SLOT(checkboxclicked()));
    To copy to clipboard, switch view to plain text mode 

    and is checkboxclicked declared as a slot?

    EDIT: and mybe you also want:
    Qt Code:
    1. connect(ui->checkbox, SIGNAL(stateChanged(int)), this, SLOT(checkboxclicked(int)));
    To copy to clipboard, switch view to plain text mode 

  13. #11
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Saving a password in a file

    thanks for ur reply

  14. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Saving a password in a file

    I'd use toggled() instead of stateChanged().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #13
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Saving a password in a file

    Quote Originally Posted by Lykurg View Post
    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?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. How to secure a file by password
    By miraks in forum Qt Programming
    Replies: 8
    Last Post: 22nd March 2011, 19:34
  2. Replies: 2
    Last Post: 21st August 2009, 23:09
  3. Saving QLabel content in a file
    By Caius Aérobus in forum Newbie
    Replies: 1
    Last Post: 29th October 2008, 17:03
  4. Filtering blank spaces while saving file names
    By jyoti kumar in forum Qt Programming
    Replies: 1
    Last Post: 3rd September 2007, 06:53
  5. QHttp GET File & Password
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 11th June 2006, 13:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.