Search code examples
whmcs

Whmcs auto auth


We are currently using auto auth and we have the method below to log in the user automatically using there email, the problem is when the email has a plus sign it will not login automatically.

/**
 * @param $email Clients Email Address to Login
 * @param string $goto is a url endpoint where you want to redirect the user
 */
public static function autoLoginUser( $email, $goto = 'index.php?m=dashboard' )
{
    global $CONFIG;

    /**
     * Define WHMCS url and AuthKey from confguration.php
     */
    $whmcsurl = $CONFIG['SystemURL'] . "/dologin.php";
    $autoauthkey = "Our auth key is here"; //$autoauthkey from configuration.php

    $timestamp = time(); //Get current timestamp
    $hash = sha1($email . $timestamp . $autoauthkey); //Generate Hash

    /**
     * Generate AutoAuth URL & Redirect
     */
    $url = $whmcsurl . "?email=$email&timestamp=$timestamp&hash=$hash&goto=" . urlencode($goto);
    header("Location: $url");
    exit;
}

Does anyone have tried this before? Having a normal email address works perfectly but on email that contains plus sign it won't log the user automatically.


Solution

  • I don't know why it was not documented in whmcs but the work around we manage to have is encode the email like the following code

    /**
     * @param $email Clients Email Address to Login
     * @param string $goto is a url endpoint where you want to redirect the user
     */
    public static function autoLoginUser( $email, $goto = 'index.php?m=dashboard' )
    {
        global $CONFIG;
    
        /**
         * Define WHMCS url and AuthKey from confguration.php
         */
        $whmcsurl = $CONFIG['SystemURL'] . "/dologin.php";
        $autoauthkey = "Our auth key is here"; //$autoauthkey from configuration.php
    
        $timestamp = time(); //Get current timestamp
        $hash = sha1($email . $timestamp . $autoauthkey); //Generate Hash
        $email = 
        /**
         * Generate AutoAuth URL & Redirect
         */
        $url = $whmcsurl . "?email=".urlencode($email)."&timestamp=$timestamp&hash=$hash&goto=" . urlencode($goto);
        header("Location: $url");
        exit;
    }