[SOLVED] hash passwords

  • 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.

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

  • 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.


  • Hi,

    in Qt4 you can always use QCryptographicHash

  • 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

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

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

    • 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)'

  • @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.


  • thanks. It works.

Log in to reply