Ask a questionAsk a question
 

AnswerLive ID SDK 1.0: Error using PHP sample

  • Thursday, August 16, 2007 9:08 AMZaarin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I've tried using the PHP sample but get the following error when trying to open /sample/index.php

    Fatal error: Call to undefined function mhash() in /home/..(trimmed)../webauth/lib/windowslivelogin.php on line 768

    Any suggestions?

Answers

  • Thursday, August 16, 2007 9:31 AMAlex MediaMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    You (or your host) is missing the mcrypt-module. Try installing/loading that module and try again Smile

     

    mcrypt provides several functions required for Live ID's security (such as the AES-encryption). If this security was absent everybody could present itself just by using a simple form.

     

    According to MSDN, you need apache2, apache2-mod_PHP5, php5-mhash, php5-mcrypt, php5-openssl, php5-dba, php5-hash, and php5-dom. You can check which modules you have by creating a file called phpinfo.php with this contents:

     

    Code Snippet

    <?php

    phpinfo();

    ?>

     

     

    Look at the output (or provide a URL here) to check which modules are missing. Smile

     

     

     

    (I'm writing a system like Windows Live ID myself, so I fully realize the importance of security)

All Replies

  • Thursday, August 16, 2007 9:31 AMAlex MediaMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    You (or your host) is missing the mcrypt-module. Try installing/loading that module and try again Smile

     

    mcrypt provides several functions required for Live ID's security (such as the AES-encryption). If this security was absent everybody could present itself just by using a simple form.

     

    According to MSDN, you need apache2, apache2-mod_PHP5, php5-mhash, php5-mcrypt, php5-openssl, php5-dba, php5-hash, and php5-dom. You can check which modules you have by creating a file called phpinfo.php with this contents:

     

    Code Snippet

    <?php

    phpinfo();

    ?>

     

     

    Look at the output (or provide a URL here) to check which modules are missing. Smile

     

     

     

    (I'm writing a system like Windows Live ID myself, so I fully realize the importance of security)

  • Saturday, August 25, 2007 9:41 PMDonauYa Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    I also encountered this problem. It seems not possible to ask the hosting guy to install these modules for me.
  • Saturday, August 25, 2007 9:46 PMAlex MediaMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Then you have no option besides switching hosts or using another domain just for handling the authentication... but I don't recommend that as it introduces another Single Point of Failure...

  • Saturday, August 16, 2008 3:52 PMwely_live Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Alex,

     

    I am also facing this problem. Could you please show / guide me what should be done in order to solve the solution? What should I install? Where can I find the module?

     

    Thanks

     

  • Saturday, August 16, 2008 4:02 PMAlex MediaMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You need the mhash and mcrypt modules. You can enable these by changing your php.ini, you'll find a lot of lines there, starting with ;extension=. You'll need to uncomment (remote the semicolon) these two lines:
    ;extension=php_mcrypt.dll
    ;extension=php_mhash.dll

    After that, you should be able to use Windows Live ID.


    However, if you're not able to edit your php.ini-file (because you're on shared hosting, for example) you need to contact your hosting provider and ask them to make the necessary changes.
  • Saturday, August 16, 2008 4:43 PMwely_live Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    Hi Alex,

     

    Thanks for the reply. But it doesn't seem that it could solve the probelm. I've tried it, but still get the error

     

    Fatal error: Call to undefined function mhash() in C:\xampp\htdocs\webauth\lib\windowslivelogin.php on line 1515

     

    Note: I tried both by using XAMPP and also FastCgi on IIS. After I edited the php.ini, I have already restarted the web server.

     

    Please help.

  • Sunday, August 17, 2008 5:00 AMwely_live Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Sorry, I got the answer already. It is because I modified the php.ini that located in C:\xampp\php\php.ini. While the xampp load the php.ini that is located in C:\xampp\apache\bin\php.ini.

     

    But later, I found another error again when I have successfully signed in to live, the error is

     

    Warning: dba_open(/var/tmp/webauth-php-sample-userdb) [function.dba-open]: failed to open stream: No such file or directory in C:\xampp\htdocs\webauth2\sample\userdb.php on line 23

    Anybody can help? I would very appreciate it!

     

    Thanks

  • Monday, August 18, 2008 3:38 PMAlex MediaMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Take a look at settings.php, change the path (/var/tmp/webauth-php-sample-userdb) to a path existing on your system, for example C:\xampp\webauth-php-sample-userdb. Be sure to create the file and give it sufficient write permissions.
  • Tuesday, August 04, 2009 11:36 PMAdam J. Bradley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    mhash is deprecated (in favour of hash) so it would be good to swap out this dependency some time soon!
    Adam
  • Friday, August 14, 2009 9:02 PMChuck Lowery Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Would it be possible to just replace the offending libraries. There does not seem to be a real good reason to not include support for both mhash and hash.

        private function derive($secret, $prefix)
        {
            if (!$secret || !$prefix) {
                self::fatal("Error: derive: secret or prefix is null.");
            }        
    
            $keyLen = 16;
            $key = $prefix . $secret;
    		$key = (is_callable("mhash")) ? mhash(MHASH_SHA256, $key) : hash(SHA256, $key);
    		
            $key = mhash(MHASH_SHA256, $key);
            if (!$key || (strlen($key) < $keyLen)) {
                self::debug("Error: derive: Unable to derive key.");
                return;
            }
            
            return substr($key, 0, $keyLen);
        }
    Any thoughts?
  • Tuesday, October 27, 2009 2:44 PMpatprzybilla Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I am facing the exact issue here. We re running PHP 5.3 on RHEL using the lates remi repo and mhash is no more provided. I ve tried to replace this line:

     $key = mhash(MHASH_SHA256, $key);
    with
     $key = hash('sha256', $key);

    but it doesn't work at all. tried on 2 different servers no success. Was anybody lucky with that?

    It would be nice from the MS team when they could change it to be compatible with latest PHP version.

    thanks

    patrick