Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] hash passwords
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] hash passwords

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 6.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gatz
    wrote on last edited by gatz
    #1

    Hello,
    I have to make a qt4 application that involves creating user profiles and login. For that I need a one way hashing algorithm, like bcrypt, but I can't find a qt4 library for that.

    I gave it a try to hash the passwords using QCA::Cipher but I keep getting 'undefined reference' and I'm not so sure if that does what I really need.

    If someone could give me a hint how to do it, I would be very grateful.
    Thanks

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      are you forced to use Qt4 instead of Qt5? Just curious why.

      Can you show the code having the issue you described??

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AlexRoot
        wrote on last edited by AlexRoot
        #3

        Hi,
        I've downloaded a C++ bcrypt lib for that and included it in my Qt project with the following code in my .pro file:
        Edit: I think this is the lib I've used: http://bcrypt.sourceforge.net/

        
        unix:!macx: LIBS += -L$$PWD/../bcrypt/ -lbcrypt
        
        INCLUDEPATH += $$PWD/../bcrypt
        DEPENDPATH += $$PWD/../bcrypt
        
        unix:!macx: PRE_TARGETDEPS += $$PWD/../bcrypt/libbcrypt.a
        

        Then I've written something like this:

        #include <bcrypt.h>
        #include <QString>
        static bool CheckPassword(const QString &_password, const QString &_hash)
        {
            QString salt(_hash.left(29));
            char test[BCRYPT_HASHSIZE];
            char hash[BCRYPT_HASHSIZE];
        
            bcrypt_hashpw(_password.toStdString().c_str(), salt.toStdString().c_str(), hash);
            bcrypt_hashpw(hash, salt.toStdString().c_str(), test);
        
            int result = 0;
            for (int i = 0; i < _hash.length(); i++)
                result |= _hash.toStdString().c_str()[i] ^ test[i];
            return result == 0;
        }
        

        It's not perfect, but it's enough for most cases.

        Regards
        AlexRoot

        1 Reply Last reply
        1
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          Hi,

          in Qt4 you can always use QCryptographicHash

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gatz
            wrote on last edited by gatz
            #5

            Is an application that must run on desktop and raspbian. Unfortunately raspbian by default comes with qt4.
            QCryptographicHash has only md4/5, sha1.
            I'm following this example http://delta.affinix.com/docs/qca/ciphertest_8cpp-example.html#_a7

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mcosta
              wrote on last edited by
              #6

              What error you're getting?
              Have you linked the library to the App?

              As suggested by @AlexRoot , you could try also with bcrypt

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              1 Reply Last reply
              0
              • G Offline
                G Offline
                gatz
                wrote on last edited by
                #7
                • I installed libqca2 from repo (using ubuntu 15.04),

                • On LoginWindow.cpp I do
                  #include <QtCrypto/QtCrypto>
                  (if I include only <QtCrypto> I get No such file or directory)

                • and I get this error for all QCA calls
                  undefined reference to `QCA::Initializer::Initializer(QCA::MemoryMode, int)'

                A 1 Reply Last reply
                0
                • G gatz
                  • I installed libqca2 from repo (using ubuntu 15.04),

                  • On LoginWindow.cpp I do
                    #include <QtCrypto/QtCrypto>
                    (if I include only <QtCrypto> I get No such file or directory)

                  • and I get this error for all QCA calls
                    undefined reference to `QCA::Initializer::Initializer(QCA::MemoryMode, int)'

                  A Offline
                  A Offline
                  AlexRoot
                  wrote on last edited by
                  #8

                  @gatz
                  Like I wrote in my last post:
                  you need a few lines in your .pro file. With these lines you tell can tell the linker to link against your lib.
                  Just open your project file, right click in it and select "Add library...", then External Library.
                  Now you can set the include path and the library file and select your target systems.

                  Cheers
                  AlexRoot

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    gatz
                    wrote on last edited by
                    #9

                    thanks. It works.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved