PDA

View Full Version : Joomla 1.5 password hash Class 1.0 for QT using C++



RajabNatshah
6th October 2009, 16:49
Hi All QT Developers

This is a Class I mad for some Projects.
I need it Under the Development work in some point.

I wanted to shear it with you all
to make use of it in your applications which you may need to
have access to Joomla Database and Connect it using QT Library.
using C++.. to work at Windows,Linux, Unix, MAC or Mobiles as will..
http://www.vc4arab.com/images/qt.png

For Example if you have database connected to Joomla 1.5
and has got the database structure,
But in your application you need to pass the username and password
and you need this tool to decrypt the password users type in your applications

This Class will help you decrypt the password or Create a new password for Joomla.
if you want your application to add new users to Joomla. so the user will be able to login
to the site even if they registered using your application.

As the Application can be downloaded and installed. but in some point we need to verify that user is in our Joomla database or not and the password is correct or not..


File joomla15passwordhash.h


/* Joomla 1.5 password hash Class 1.0
* Copyright
* Smart Neural Tech LTD
* www.smartneural.com
* rajab@smartneural.com
*
* Developer Name: Rajab Natshah
* rajab@natshah.com
*
* This Class helps you use username and passwords
* from the Joomla 1.5 database Cryptographic Hash using QT Library.
* And C++ Class.
*
*/

#ifndef JOOMLA15PASSWORDHASH_H
#define JOOMLA15PASSWORDHASH_H
//
#include <stdlib.h>
#include <time.h>
#include <QString>
#include <QStringList>
#include <QByteArray>
#include <QCryptographicHash>
//
class Joomla15PasswordHash
{
private:

public:
Joomla15PasswordHash();
bool check(QString passwd,QString dbEntry);
QString create(QString passwd);
QString md5(QString data);
};
#endif




File joomla15passwordhash.cpp


/* Joomla15passwordhash Class 1.0
* Copyright
* Smart Neural Tech LTD
* www.smartneural.com
* rajab@smartneural.com
*
* Developer Name: Rajab Natshah
* rajab@natshah.com
*
* This Class helps you use username and passwords
* from the Joomla 1.5 database Cryptographic Hash using QT Library.
* And C++ Class.
*
*/



#include "joomla15passwordhash.h"
//
Joomla15PasswordHash::Joomla15PasswordHash()
{

}
bool Joomla15PasswordHash::check(QString passwd,QString dbEntry)
{

// new format as {HASH}:{SALT}
QStringList aar = dbEntry.split(":");
QString cryptpass = aar[0];
QString salt = aar[1];
bool result = (md5(passwd+salt) == cryptpass);
return result ;

}

QString Joomla15PasswordHash::create(QString passwd)
{
QString salt;
int _rnd;
srand ( time(NULL) );
for (int i=0;i<32;i++)
{
_rnd = rand()%36+1;
salt.append(QString::number(_rnd,36));
}
return md5(passwd+salt)+":"+salt;
}

QString Joomla15PasswordHash::md5(QString data) {
QByteArray bdata;
bdata.resize(data.length());
int i;
QByteArray hash;

bdata = data.toUtf8();
for (i=0;i<data.length();i++)
bdata[i]= bdata[i]&0xff;

hash = QCryptographicHash::hash(bdata, QCryptographicHash::Md5);

QString r;

for (i=0;i<hash.length();i++) {
QString x = QString::number(hash[i]&0xff,16);
if (x.length()<2) r.append("0");
r.append(x);
}

return r;
}
//



I hope you can use it in your projects.
and any help I'm available.

I have attached the files so you can use them directly in your Development under QT Library

Best Regards
Rajab Natshah :)