How to resolve the empty confirmCode issue in Joomla

I was working on a client website based on Joomla. When any member registered on the website an email was sent to the member’s email address to verify his account. The email was coming up fine but the confirmCode variable in the query string was empty. Client wanted me to resolve it so I set to work on it.

The email text was generated from the administrator/components/com_comprofiler/comprofiler.class.php file. The function generating the email text is _replaceVariables. There is one function by that name in the file so you can just do Ctrl-F and do a search for it. For some reason, there was a check in the file as follows

if ( $row->cbactivation ) {
         $confirmCode = $row->cbactivation;
else {
         $confirmCode = '';

No guessing here. The code was always going to the else condition as the $row->cbactivation was empty. After going through the code, I found that the encryption code was being generated but not saved in the cbactivation column in the jos_comprofiler table. Due to this the confirmCode was always empty.

The best solution I came up with was generate the code, save it in the database and send it to the member from the same function i.e. _replaceVariables. I copied over the encryption code and altered the code in the else block to the following:

//$confirmCode = '';
$row->cbactivation = "reg" . md5( cbMakeRandomString() ) . sprintf( "%08x", ((int) hexdec(substr( md5 ( $mainframe->getCfg( 'secret' ) . $mainframe->getCfg( 'db' ) ), 0, 7))) ^ ( (int) $row->id ) ); 
$_CB_database->setQuery( "UPDATE #__comprofiler SET cbactivation='".$row->cbactivation."' WHERE user_id='".$row->id."' " );
$confirmCode = $row->cbactivation;	

The code above generates the encryption code and saves it into the database which is what I wanted. I registered a member on the website and voila I got the email with the confirmCode coming up. I clicked on the URL and my account was also confirmed.

I also got some help from the following solution at JoomlaPolis.

Hope the above helped.

Leave a Comment