PHP

You are currently browsing the archive for the PHP category.

I was in need of a PHP class to encrypt hash and verify passwords using salted sha1 hashes. Here it is, quick but not too dirty:

<?php

class SSHA
{

  public static function newSalt()
  {
    return chr(rand(0,255)).chr(rand(0,255)).chr(rand(0,255)).chr(rand(0,255));
  }

  public static function hash($pass,$salt)
  {
    return '{SSHA}'.base64_encode(sha1($pass.$salt,true).$salt);
  }

  public static function getSalt($hash)
  {
    return substr(base64_decode(substr($hash,-32)),-4);
  }

  public static function newHash($pass)
  {
    return self::hash($pass,self::newSalt());
  }

  public static function verifyPassword($pass,$hash)
  {
    return $hash == self::hash($pass,self::getSalt($hash));
  }

}

- 85.3 KB yeah, right.

July 4, 2008 | No comments

This is a quicky: If you have Windows Vista and XAMPP and your “CLI has stopped working” you need to download the PHP binaries (Windows Binaries, zip package) from php.net and replace the php_mysqli.dll in C:\xampp\php\ext with the version you just downloaded. Downloading the latest version of PHP should work just fine, even if an older version was previously installed on your system. – I know this seems weird, but it works. If you want a longer explanation, read Tengku Zahasman’s article on the same subject, with the comments. (I found the article using Google.)