Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Login System :



  • I'm using Qt creator and i'm trying to do a login system about the administrator of my database in MySql
    I dont now how to compare my values(name and password,which I have in a class called Admin) with the real values on database.
    Anyone could help pls ?



  • Your database user table should contain logins, salted password hashes and randomly generated "salts":https://en.wikipedia.org/wiki/Salt_(cryptography).
    User authentication would involve a SELECT query for a password hash and a salt of the corresponding login (for example given by user in the login window), and a comparison of password hash from the database with the given password, concatenated with salt and hashed.

    Basically, perform a SELECT, save the query result in QStrings and follow the above.



  • Here is my code:
    @#include<QSqlDatabase>
    #include<QSqlQuery>
    #include<iostream>
    #include<Database.cpp>
    #include<Administratori.cpp>
    using namespace std;
    class Votuesi
    {
    public:

    string v_id ,emer,mbiemer,atesia,qarku,pass;
    public:
    Votuesi(string id,string qark,string pas)
    {
    v_id=id;
    qarku=qark;
    pass=pas;
    }
    void identifikohu()
    {

    QString sQuery=("SELECT * FROM evoting WHERE v_id = ? AND qyteti = ? AND pass = ? ");
    

    QSqlQuery query3;
    query3.prepare(sQuery);
    query3.addBindValue(v_id);
    query3.addBindValue(qarku);
    query3.addBindValue(pass);
    query3.exec();
    if (query3.size()>0)
    {
    qDebug() <<"Identifikimi u krye me sukses,ju jeni nje votues i vlefshem";}
    else
    {
    qDebug() <<"Te dhenat tuaja jane te pasakta";
    }
    }
    };

    int main()
    {
    Database db;
    db.lidhDatabase();
    Votuesi votuesi("12345","Rome","Ana");
    votuesi.identifikohu();
    }@

    The problem is on line 25,26,27..I can't take the values from my constructor to make a comparison with those values in database



  • What do you mean that you can't? What is the actual outcome and the expected one?

    On a side note, you should be using QStrings and by any chance not mix them up with STD strings.


Log in to reply