password

Forum for posting problems using QxOrm library

password

Postby ruddy32 » Thu Mar 10, 2011 3:38 pm

Hello,
Is it possible to defined an encrypted storage column? How?
Maybe my app must encrypt before storing ?
Thanks
ruddy32
 

Re: password

Postby QxOrm admin » Thu Mar 10, 2011 7:30 pm

Hi,

I think there is many ways to resolve your encryption problem.

Here an easy solution :
1- define a BLOB column in your database (to store encrypted data of QByteArray type)
2- define a private QString property "m_password" in your persistent class (password not encrypted, so this is a transient property => you must not register this property in your mapping function : void qx::register_class(...))
3- define a private QByteArray property "m_encryptedPassword" in your persistent class (this is the encrypted password, so a persistent property => you must register this property in your mapping function : void qx::register_class(...))

Properties "m_password" and "m_encryptedPassword" are private, so you need to implement accessors get and set like this :

Code: Select all
void my_class::setPassword(const QString & sPassword)
{
   m_password = sPassword;
   m_encryptedPassword = EncryptFromQStringToQByteArray(m_password); // search on google, there is a lot of encryption engine for the QByteArray type...
}

Code: Select all
QString my_class::getPassword()
{
   // If you load your persistent class, you have only a value into the property "m_encryptedPassword"
   if (m_password.isEmpty() && ! m_encryptedPassword.isEmpty())
   { m_password = DecryptFromQByteArrayToQString(m_encryptedPassword); }
   return m_password;
}


You can also use the trigger mechanism of QxOrm library if you want to execute some code before storing any object (see the FAQ for triggers...).
If you have other ideas, you can post your solution or evolution for QxOrm library... ;)
QxOrm admin
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 5 guests